[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gperf] Bug in in_word_set GNU gperf 3.0.4
From: |
Bruno Haible |
Subject: |
Re: [bug-gperf] Bug in in_word_set GNU gperf 3.0.4 |
Date: |
Sat, 26 Nov 2016 17:37:36 +0100 |
User-agent: |
KMail/4.8.5 (Linux/3.8.0-44-generic; KDE/4.8.5; x86_64; ; ) |
Hor Meng Yoong wrote in
<http://lists.gnu.org/archive/html/bug-gperf/2014-07/msg00001.html>:
> I use this code: *calendar.gperf*
>
> %{
> #include <stdio.h>
> #include <string.h>
> /* Command-line options:
> -C -p -a -n -t -o -j 1 -k 2,3
> -N is_month */
> %}
> struct months {
> char *name;
> int number;
> int days;
> int leap_days;
> };
> %%
> january, 1, 31, 31
> february, 2, 28, 29
> march, 3, 31, 31
> april, 4, 30, 30
> may, 5, 31, 31
> june, 6, 30, 30
> july, 7, 31, 31
> august, 8, 31, 31
> september, 9, 30, 30
> october, 10, 31, 31
> november, 11, 30, 30
> december, 12, 31, 31
> %%
> /* Auxiliary code goes here... */
> int main () {
> int hash_value = hash("may", sizeof("may"));
> printf("Hash value of may is %d\n", hash_value);
> printf("may is in hash function = %s", in_word_set("may", sizeof("may")));
> }
>
> $ gperf calendar.gperf > calendar.c
> $ gcc -o calendar calendar.c
> $ ./calendar
> Hash value of may is 4
> may is in hash function = (null)
sizeof("may") is 4, because it includes the trailing NUL byte. But none
of the words in the word set includes a trailing NUL byte; that's why it isn't
being found.
I'd suggest to use 'strlen' instead of 'sizeof' on string literals.
Bruno
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: [bug-gperf] Bug in in_word_set GNU gperf 3.0.4,
Bruno Haible <=