Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tautological-compare in trietool.c #3

dmacks opened this issue Sep 20, 2016 · 1 comment

tautological-compare in trietool.c #3

dmacks opened this issue Sep 20, 2016 · 1 comment


Copy link

dmacks commented Sep 20, 2016

Building libdatrie-0.2.10 on OS X 10.11, I get a warning:

gcc -DHAVE_CONFIG_H -I. -I.. -I.. -I/sw/include -g -O2 -MT trietool.o -MD -MP -MF .deps/trietool.Tpo -c -o trietool.o trietool.c
trietool.c:128:13: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]
if (res < 0)
~~~ ^ ~
1 warning generated.

res is (correctly per iconv prototype) a size_t, but size_t is generally some sort of unsigned int: the warning seems on target. The iconv manpage says that the return in case of error isn't "-1" but is "(size_t)(-1)": -1 cast to the return type. And its example code is:

size_t nconv;
nconv = iconv (cd, &inptr, &insize, &wrptr, &avail);
if (nconv == (size_t) -1) ...

So trietool.c at line 128 should be changed:

-    if (res < 0)
+    if (res == (size_t) -1)
         return res;
thep added a commit that referenced this issue Sep 21, 2016
* tools/trietool.c (conv_to_alpha):
  - Check iconv() return value against (size_t) -1, rather than
    for its negativity, as size_t can be unsigned.

Thanks Daniel Macks for the report on Issue #3.
Copy link

thep commented Sep 21, 2016

Fix has been committed. Thanks for your report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

No branches or pull requests

2 participants