<<< Date Index >>>     <<< Thread Index >>>

Re: [PATCH 4 of 9] Fix comparison signedness warnings



On Sat, Aug 07, 2010 at 10:10:16AM +0200, Matthias Andree wrote:
Am 07.08.2010, 07:46 Uhr, schrieb Michael Elkins:
Alternate version with addition check to make sure cast is safe.

-    if (!first && pos + strlen (path) >= COLS - 7)
+ if (!first && (COLS - 7 >= 0) && (pos + strlen (path) >= (size_t)COLS - 7))

Good catch. I was assuming that. Depending on compiler, it will be more efficient to write COLS >= 7 :)

Would something like

/* compare the first size_t argument a to the signed-typed argument b */
#define SIZET_GE(a, b)  ((b) >= 0 && (a) >= (size_t)(b))
#define SIZET_GT(a, b)  ((b) >= 0 && (a) > (size_t)(b))

These should probably just be inline functions rather than macros. I almost went that route when considering all of your patches. I'm not sure it is worth the effort, though, since there are just a handful of places where it is required.

me

Attachment: pgp1ubVoITv9W.pgp
Description: PGP signature