# # patch "ChangeLog" # from [83dad125b9c1a36f788f6838f9c58470205abfe5] # to [6ad1dc6095eb78b8a13b862a164bbb2278b887d6] # # patch "sanity.hh" # from [a76c195983868ec89e1f3334845c4a875c9b9a51] # to [56b8f42b629be5332bdc2aa2f142ec64a5699859] # --- ChangeLog +++ ChangeLog @@ -1,5 +1,8 @@ 2005-04-27 Richard Levitte + * sanity.hh: Add a couple of variants of checked_index() to + accomodate for indexes over vector. + * commands.hh: Add new selector to find arbitrary cert name and value pairs. The syntax is 'c:{name}={value}'. * commands.cc (decode_selector): Recognise it. --- sanity.hh +++ sanity.hh @@ -16,6 +16,8 @@ #include // Required for ENABLE_NLS #include "gettext.h" +#include "quick_alloc.hh" // to get the QA() macro + #ifdef __GNUC__ #define NORETURN __attribute__((noreturn)) #else @@ -156,7 +158,33 @@ return v[i]; } +template +inline T & checked_index(std::vector & v, + typename std::vector::size_type i, + char const * vec, + char const * index, + char const * file, + int line) +{ + if (UNLIKELY(i >= v.size())) + global_sanity.index_failure(vec, index, v.size(), i, file, line); + return v[i]; +} +template +inline T const & checked_index(std::vector const & v, + typename std::vector::size_type i, + char const * vec, + char const * index, + char const * file, + int line) +{ + if (UNLIKELY(i >= v.size())) + global_sanity.index_failure(vec, index, v.size(), i, file, line); + return v[i]; +} + + #define idx(v, i) checked_index((v), (i), #v, #i, __FILE__, __LINE__)