skydevgit / crisscross

Automatically exported from code.google.com/p/crisscross
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

wrong return type for LinkedList find method #40

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
In crisscross/llist.h and crisscross/llist.cpp, the return type, `size_t`,
for the find method of the LList class is incorrect. `size_t` is an
*unsigned* integer type and find returns -1 (a *signed* integer) when it
doesn't find the data given.

The return type could be changed to a signed integer type (ssize_t maybe?),
or the value returned could be the length of the list or some value that
isn't being used as an index so that the return type is unchanged.

Original issue reported on code.google.com by omo...@gmail.com on 28 Mar 2010 at 2:16

GoogleCodeExporter commented 9 years ago
Some more info...the only reason `get(find(nonExistantData)) == NULL` works is
because the conversion of -1 from signed integer to an unsigned integer is 
still out
of bounds of the list. However, the return type is still wrong because the find 
is
returning some random large number instead of -1.

Thus `find(nonExistantData) == (size_t)-1` will work, but 
`find(nonExistantData) ==
-1` will not work because of the types and if you try to test around that by 
using
`find(nonExistantData) < 0`, then you'll see that a positive number is returned.

Original comment by omo...@gmail.com on 28 Mar 2010 at 4:53

GoogleCodeExporter commented 9 years ago
I fixed this issue in my own fork here:
http://github.com/omouse/crisscross/commit/2c98ec0fe71ea7a31f753eb8703ca7e2d13ec
239

Original comment by omo...@gmail.com on 25 Apr 2010 at 9:45