Re: Redundant validity check in stock code.

From: Thomas Arp (t_arp@stofanet.dk)
Date: 07/25/02


From: "George Greer" <greerga@CIRCLEMUD.ORG>
> On Thu, 25 Jul 2002, Thomas Arp wrote:
>
> >Hey all,
> >
> >A couple of places in the code, there is a redundant check for
> >validity of a variable. In all cases, the check refers to
> >
> >nlen < 0
> >
> >where nlen is a size_t (which is unsigned). Also, as you can see
> >from the below code, nlen must be initialized to a positive number
> >(or 0) before this line, as snprintf() always returns a positive
> >number or 0.
>
> It's supposed to be 'int', so I must've messed them up.
>

http://www.fsf.org/manual/glibc-2.0.6/html_node/libc_94.html :
int snprintf (char *s, size_t size, const char *template, ...)

You'll want to keep the size_t. As the docs state, snprintf returns
the amount of characters written, which is always >= 0.

Welcor

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   | Newbie List:  http://groups.yahoo.com/group/circle-newbies/   |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 06/25/03 PDT