Re: snprintf(3) example warns under -Wextra

2017-04-23 Thread Timo Buhrmester
On Mon, Apr 24, 2017 at 12:01:10AM +0200, Marc Espie wrote: > On Sun, Apr 23, 2017 at 10:16:38PM +0200, Timo Buhrmester wrote: > > > The main difference between you and Theo is that Theo knows what he's > > > talking about. > > > If you want to contribute anything, point out how casting a

Re: snprintf(3) example warns under -Wextra

2017-04-23 Thread Marc Espie
On Sun, Apr 23, 2017 at 10:16:38PM +0200, Timo Buhrmester wrote: > > The main difference between you and Theo is that Theo knows what he's > > talking about. > If you want to contribute anything, point out how casting a non-negative > into to size_t for comparison against another size_t could

Re: snprintf(3) example warns under -Wextra

2017-04-23 Thread Timo Buhrmester
> The main difference between you and Theo is that Theo knows what he's > talking about. If you want to contribute anything, point out how casting a non-negative into to size_t for comparison against another size_t could lead to "real errors later whenever the code evolves in any way". Nice

Re: snprintf(3) example warns under -Wextra

2017-04-23 Thread Marc Espie
On Sun, Apr 23, 2017 at 05:12:16PM +0200, Timo Buhrmester wrote: > Except if the world changes... In a way that's still POSIX-compliant. > But why would anyone want to protect themselves from that, right? You're full of it. You're advocating for an unnecessary cast that can actually hide real

Re: snprintf(3) example warns under -Wextra

2017-04-23 Thread Timo Buhrmester
> Timo if you feel the need to be an asshole, please be that asshole > elsewhere. Pot, meet Kettle.

Re: snprintf(3) example warns under -Wextra

2017-04-23 Thread Theo de Raadt
> > Otherwise, you can start enabling that option and sending a diff which > > fixes ALL THE WARNINGS IT GIVES IN THE ENTIRE TREE. > I think I'll pass on that. I wasn't aware of how many warnings > a build seems to cause. This must be why NetBSD has -Werror in their > CFLAGS. Timo if you feel

Re: snprintf(3) example warns under -Wextra

2017-04-23 Thread Timo Buhrmester
> > Otherwise people might fall into a habit > > of ignoring warnings [that may point to actual problems]. > > People might fall into the habit of ignoring a warning from an > extension to C provided by a single compiler? > > I doubt it. Doubt away. I find it more than obvious that telling

Re: snprintf(3) example warns under -Wextra

2017-04-23 Thread Theo de Raadt
> > The code is already safe. > It is reasonably safe(*) and triggers a warning. That's a good reason > to silence the warning. No. The warning is a false extension to C. In C, int and sizeof can be compared safely in this circumstance. > Otherwise people might fall into a habit > of ignoring

Re: snprintf(3) example warns under -Wextra

2017-04-23 Thread Timo Buhrmester
> The code is already safe. It is reasonably safe(*) and triggers a warning. That's a good reason to silence the warning. Otherwise people might fall into a habit of ignoring warnings [that may point to actual problems]. I just pointed out a safe way to silence the warning, without it

Re: snprintf(3) example warns under -Wextra

2017-04-23 Thread Theo de Raadt
> > Well, when the world changes, that cast is suddenly wrong. > > I.e. instead of > > if (ret == -1 || ret >= sizeof(buffer)) > one could use > > if (ret < 0 || (size_t)ret >= sizeof(buffer)) > > And be safe from a changing world. The code is already safe.

Re: snprintf(3) example warns under -Wextra

2017-04-23 Thread Timo Buhrmester
> Well, when the world changes, that cast is suddenly wrong. I.e. instead of > if (ret == -1 || ret >= sizeof(buffer)) one could use > if (ret < 0 || (size_t)ret >= sizeof(buffer)) And be safe from a changing world.

Re: snprintf(3) example warns under -Wextra

2017-04-22 Thread Theo de Raadt
-Wextra is stupid. It is trying to persuade patterns that ignore the rules of standard C. In particular for this situation: Never add extra costs. Adding casts everywhere is HIGHLY ERROR PRONE. Unneccesary casts were among the hardest parts of the jump from 32-bit to 64-bit, since a cast means

snprintf(3) example warns under -Wextra

2017-04-22 Thread Matthew Martin
The example proper usage of snprintf(3) (under Caveats) evokes a warning when compiled with -Wextra. I presume casting ret to unsigned int would be safe, but I'll defer to those who know the nuances. #include int foo(char* string) { char buffer[128]; int ret = snprintf(buffer,