[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: read in movemail.c

From: Jan D.
Subject: Re: read in movemail.c
Date: Fri, 05 May 2006 14:55:24 +0200
User-agent: Mozilla Thunderbird 1.0.7 (X11/20050923)

Dan Nicolaescu wrote:

CID: 29
Checker: NEGATIVE_RETURNS (help)
File: emacs/lib-src/movemail.c
Function: main
Description: Tracked variable "nread" was passed to a negative sink.

463           {
464             char buf[1024];
466             while (1)
467               {

Event negative_return_fn: Called negative-returning function "read"
Event var_assign: NEGATIVE return value of "read" assigned to signed variable 
Also see events: [var_assign][negative_returns]

468                 nread = read (indesc, buf, sizeof buf);

Event negative_returns: Tracked variable "nread" was passed to a negative sink.
Also see events: [negative_return_fn][var_assign]

469                 if (nread != write (outdesc, buf, nread))
470                   {
471                     int saved_errno = errno;
472                     unlink (outname);
473                     errno = saved_errno;
474                     pfatal_with_name (outname);
475                   }
476                 if (nread < sizeof buf)
477                   break;

Is it portable to just pass "nread" to write and compare the return
values? Maybe "nread" can be checked before?

nread might be -1 on error from read, so then the call to write would be bad, as the third argument is a size_t (unsigned) so -1 becomes a large value. Better is to check for -1 and 0 (end of file) before doing the write.

   Jan D.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]