Re: [PATCH] Fix a GCC warning: comparing signed vs. unsigned

2014-05-20 Thread Scott Kostyshak
On Mon, May 19, 2014 at 3:09 PM, Georg Baum wrote: > Please be careful with "never expected to be large". The warning you are > adressing is about a subtle error which usually does not occur, but there is > a small chance that it can occur. When fixing warnings like that I very much > prefer to f

Re: [PATCH] Fix a GCC warning: comparing signed vs. unsigned

2014-05-19 Thread Georg Baum
Am Dienstag, 20. Mai 2014 schrieb Cyrille Artho: > > It is the correct type on linux as well. Therefore, the approach > > suggested by Cyrille is IMHO the best one: Change the type of nRead > > to ssize_t (note the two s), and change the if-condition to > > > > if (static_cast(nRead) < buf.size()

Re: [PATCH] Fix a GCC warning: comparing signed vs. unsigned

2014-05-19 Thread Cyrille Artho
It is the correct type on linux as well. Therefore, the approach suggested by Cyrille is IMHO the best one: Change the type of nRead to ssize_t (note the two s), and change the if-condition to if (static_cast(nRead) < buf.size() - 1) { This is 100% safe: We know that nRead > 0 at the time the

Re: [PATCH] Fix a GCC warning: comparing signed vs. unsigned

2014-05-19 Thread Georg Baum
Cyrille Artho wrote: > Scott Kostyshak wrote: >> On Sun, May 18, 2014 at 7:58 PM, Richard Heck wrote: >>> On 05/18/2014 07:22 PM, Scott Kostyshak wrote: Is this OK? Note that converting the left hand side to an unsigned int would work also, because it was checked just above that nR

Re: [PATCH] Fix a GCC warning: comparing signed vs. unsigned

2014-05-18 Thread Cyrille Artho
Scott Kostyshak wrote: On Sun, May 18, 2014 at 7:58 PM, Richard Heck wrote: On 05/18/2014 07:22 PM, Scott Kostyshak wrote: Is this OK? Note that converting the left hand side to an unsigned int would work also, because it was checked just above that nRead is >=0. But I figure converting the s

Re: [PATCH] Fix a GCC warning: comparing signed vs. unsigned

2014-05-18 Thread Scott Kostyshak
On Sun, May 18, 2014 at 7:58 PM, Richard Heck wrote: > On 05/18/2014 07:22 PM, Scott Kostyshak wrote: >> >> Is this OK? Note that converting the left hand side to an unsigned int >> would work also, because it was checked just above that nRead is >=0. >> But I figure converting the signed to unsig

Re: [PATCH] Fix a GCC warning: comparing signed vs. unsigned

2014-05-18 Thread Richard Heck
On 05/18/2014 07:22 PM, Scott Kostyshak wrote: Is this OK? Note that converting the left hand side to an unsigned int would work also, because it was checked just above that nRead is >=0. But I figure converting the signed to unsigned is better in general as long as the numbers are not expected t