curl-library
Re: Array Index size_t vs int
Date: Mon, 17 Sep 2012 22:27:00 +0200 (CEST)
On Mon, 17 Sep 2012, Marc Hoersken wrote:
> I noticed that quite some warnings in the curl source code are related to
> size_t/ssite_t to int conversions. This is caused by the fact that we are
> mostly using int-typed indexes to access array fields there the actual array
> holds a string- or data-buffer. Many of the functions operating on these
> buffers return size_t/ssize_t values, for example strlen:
> http://linux.die.net/man/3/strlen
Let me just remind everyone that we compile libcurl on MANY different and even
ancient systems so we cannot even always rely on proper POSIX compliance
(which unfortunately also includes Windows). Hence there may be some funny
actions to minimize warnings on stupid old legacy unixes. Our autobuilds show
some of them.
> Curl uses multiple ways to deal with some of those warnings. One of them is
> to do type-conversion or use the helper functions provided within
> warnless.h. I think this might be the wrong way to deal with this specific
> problem. As you can see in the discussion of the following StackOverflow
> question, size_t/ssize_t can actually be used for array access:
The best way to handle variable types is to as much as possible retain the
same type. But our POSIX/non-POSIX support mix make that a very interesting
challenge.
Also, remember that for example printf()ing size_t and ssize_t is an
interesting task to do warning-free for a portable program. We have this
problem right now with curl_off_t in a few examples as can be seen in this
build: http://curl.haxx.se/dev/log.cgi?id=20120917184735-11714#prob1
> What do you think about this? Is this a good alternative to the existing
> strategy that should/could be used to remove the remaining warnings and may
> also be used to replace the existing type conversions?
>
> Since I am not sure if size_t/ssite_t would be a cross-platform way to solve
> this, I would like to ask for your feedback on this, too. Thanks in advance!
If you think you can fix actual warnings or errors by doing such changes then
I think doing them is good. Doing them only for correctness I think isn't
worth it but instead risks us introducing new side-effects.
> Unfortunately I cannot show some example warnings or link to the autobuilds
> page right now. At the moment it just shows up as an empty page to me.
Really? It works fine for me now in both Chrome and Firefox...
-- / daniel.haxx.se ------------------------------------------------------------------- List admin: http://cool.haxx.se/list/listinfo/curl-library Etiquette: http://curl.haxx.se/mail/etiquette.htmlReceived on 2012-09-17