Skip to content

Align types of i, n, and _ut_i#237

Open
mterron wants to merge 1 commit intotroydhanson:masterfrom
mterron:patch-2
Open

Align types of i, n, and _ut_i#237
mterron wants to merge 1 commit intotroydhanson:masterfrom
mterron:patch-2

Conversation

@mterron
Copy link

@mterron mterron commented Jan 18, 2022

On line 97 , 0 <= (j) is always true so removed that too :)

On line 97 , `0 <= (j)`  is always `true` so removed that too :)
#define _utringbuffer_real_idx(a,j) ((a)->f ? ((j) + (a)->i) % (a)->n : (j))
#define _utringbuffer_internalptr(a,j) ((void*)((a)->d + ((a)->icd.sz * (j))))
#define utringbuffer_eltptr(a,j) ((0 <= (j) && (j) < utringbuffer_len(a)) ? _utringbuffer_internalptr(a,_utringbuffer_real_idx(a,j)) : NULL)
#define utringbuffer_eltptr(a,j) (((j) < utringbuffer_len(a)) ? _utringbuffer_internalptr(a,_utringbuffer_real_idx(a,j)) : NULL)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here j could certainly be negative if it were, for example, -1, or an int that happened to have the value -1.
If you're doing this to work around a compiler warning, please file a bug/issue with a minimal compilable example that demonstrates the warning and maybe we can find a way to silence it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, here's the output from the compiler and seem to disagree with that assertion but it might be wrong.

swuniq.c: In function ‘lookup’:
uthash/src/utringbuffer.h:97:38: warning: comparison of unsigned expression >= 0 is always true [-Wtype-limits]
   97 | #define utringbuffer_eltptr(a,j) ((0 <= (j) && (j) < utringbuffer_len(a)) ? _utringbuffer_internalptr(a,_utringbuffer_real_idx(a,j)) : NULL)
      |                                      ^~
swuniq.c:133:25: note: in expansion of macro ‘utringbuffer_eltptr’
  133 |    XXH64_hash_t *item = utringbuffer_eltptr(rbuffer, i);
      |                         ^~~~~~~~~~~~~~~~~~~
swuniq.c: In function ‘main’:
uthash/src/utringbuffer.h:46:12: warning: conversion from ‘size_t’ {aka ‘long unsigned int’} to ‘unsigned int’ may change value [-Wconversion]
   46 |   (a)->n = (_n);                                                          \
      |            ^
uthash/src/utringbuffer.h:76:3: note: in expansion of macro ‘utringbuffer_init’
   76 |   utringbuffer_init(a, n, _icd);                                          \
      |   ^~~~~~~~~~~~~~~~~
swuniq.c:176:2: note: in expansion of macro ‘utringbuffer_new’
  176 |  utringbuffer_new(history, window_size, &ut_xxh64_hash_t_icd);
      |  ^~~~~~~~~~~~~~~~
uthash/src/utringbuffer.h:97:38: warning: comparison of unsigned expression >= 0 is always true [-Wtype-limits]
   97 | #define utringbuffer_eltptr(a,j) ((0 <= (j) && (j) < utringbuffer_len(a)) ? _utringbuffer_internalptr(a,_utringbuffer_real_idx(a,j)) : NULL)
      |                                      ^~
uthash/src/utringbuffer.h:55:23: note: in expansion of macro ‘utringbuffer_eltptr’
   55 |         (a)->icd.dtor(utringbuffer_eltptr(a, _ut_i));                     \
      |                       ^~~~~~~~~~~~~~~~~~~
uthash/src/utringbuffer.h:69:3: note: in expansion of macro ‘utringbuffer_clear’
   69 |   utringbuffer_clear(a);                                                  \
      |   ^~~~~~~~~~~~~~~~~~
uthash/src/utringbuffer.h:80:3: note: in expansion of macro ‘utringbuffer_done’
   80 |   utringbuffer_done(a);                                                   \
      |   ^~~~~~~~~~~~~~~~~
swuniq.c:189:2: note: in expansion of macro ‘utringbuffer_free’
  189 |  utringbuffer_free(history);
      |  ^~~~~~~~~~~~~~~~~
uthash/src/utringbuffer.h:97:38: warning: comparison of unsigned expression >= 0 is always true [-Wtype-limits]
   97 | #define utringbuffer_eltptr(a,j) ((0 <= (j) && (j) < utringbuffer_len(a)) ? _utringbuffer_internalptr(a,_utringbuffer_real_idx(a,j)) : NULL)
      |                                      ^~
uthash/src/utringbuffer.h:60:23: note: in expansion of macro ‘utringbuffer_eltptr’
   60 |         (a)->icd.dtor(utringbuffer_eltptr(a, _ut_i));                     \
      |                       ^~~~~~~~~~~~~~~~~~~
uthash/src/utringbuffer.h:69:3: note: in expansion of macro ‘utringbuffer_clear’
   69 |   utringbuffer_clear(a);                                                  \
      |   ^~~~~~~~~~~~~~~~~~
uthash/src/utringbuffer.h:80:3: note: in expansion of macro ‘utringbuffer_done’
   80 |   utringbuffer_done(a);                                                   \
      |   ^~~~~~~~~~~~~~~~~
swuniq.c:189:2: note: in expansion of macro ‘utringbuffer_free’
  189 |  utringbuffer_free(history);
      |  ^~~~~~~~~~~~~~~~~

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants