[PATCH] lib/string_map: fix return type of string_cmp

Matt Armstrong marmstrong at google.com
Mon Mar 4 17:42:39 PST 2019


David Bremner <david at tethera.net> writes:

> I can't figure out how checking the sign of a bool ever worked. The
> following program demonstrates the problem (i.e. for me it prints 1).
>
>  #include <stdio.h>
>  #include <stdbool.h>
>  int main(int argc, char **argv) {
>     bool x;
>     x = -1;
>     printf("x = %d\n", x);
>  }
>
> This seems to be mandated by the C99 standard 6.3.1.2.

Perhaps it never did work?  It looks like this function to date is used
only for properties, where I assume each message has just one or two?
With just a few elements a buggy binary search can do surprisingly well.
Don't ask me how I know this.  ;-)

Perhaps some unit tests for _notmuch_string_map would be worthwhile?


> ---
>
>  I'd like to get this in a new point release ASAP.
>
>  lib/string-map.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/lib/string-map.c b/lib/string-map.c
> index ad818207..a88404c7 100644
> --- a/lib/string-map.c
> +++ b/lib/string-map.c
> @@ -106,7 +106,7 @@ _notmuch_string_map_sort (notmuch_string_map_t *map)
>      map->sorted = true;
>  }
>  
> -static bool
> +static int
>  string_cmp (const char *a, const char *b, bool exact)
>  {
>      if (exact)
> -- 

Looks good.


More information about the notmuch mailing list