[quagga-dev 5273] Re: mes_lookup / LOOKUP robustness
Andrew J. Schorr
aschorr at telemetry-investments.com
Wed Feb 27 01:36:13 GMT 2008
On Tue, Feb 26, 2008 at 11:29:47PM +0000, Paul Jakma wrote:
> It's test lsah->type, not lsah_type - it's assuming therefore that
> ospf_lsa_type_msg has strings for every possible value. However it
> doesn't, so lsah_type could still be NULL.
Oops, sorry, I read the code too quickly.
> --- lib/log.c 6 Aug 2007 15:21:45 -0000 1.33
> +++ lib/log.c 26 Feb 2008 23:28:46 -0000
> @@ -756,10 +756,17 @@ lookup (struct message *mes, int key)
> const char *
> mes_lookup (struct message *meslist, int max, int index)
> + int shift;
> + /* key number ranges could start anywhere, e.g. 1 is typical for protocol
> + constants */
> + shift = meslist.key;
> /* first check for best case: index is in range and matches the key
> value in that slot */
> - if ((index >= 0) && (index < max) && (meslist[index].key == index))
> - return meslist[index].str;
> + if ((index >= shift) && ((index - shift) < max)
> + && (meslist[index - shift].key == index))
> + return meslist[index - shift].str;
OK, that looks pretty good. At the risk of being wrong again
(I shouldn't do code review while running a fever), would it make
more sense to do it this way?
int idx = index-meslist.key;
if ((idx >= 0) && (idx < max) && (meslist[idx].key == index))
(since we don't really care about 'shift', just 'index-shift').
More information about the Quagga-dev