----- Messaggio originale -----
> Da: Alyssa Milburn <[email protected]>
> A: Gianfranco Costamagna <[email protected]>
> Cc: "[email protected]" <[email protected]>
> Inviato: Lunedì 8 Luglio 2013 21:52
> Oggetto: Re: [boinc_dev] addressing some clang warnings
> 
man fscanf

"       These functions return the number of input items successfully matched 
and assigned, which  can  be  fewer
       than provided for, or even zero in the event of an early matching 
failure.

       The value EOF is returned if the end of input is reached before either 
the first successful conversion or
       a matching failure occurs.  EOF is also returned if a read error occurs, 
in which case the error  indica‐
       tor for the stream (see ferror(3)) is set, and errno is set indicate the 
error.
"


> On Mon, Jul 08, 2013 at 04:51:26PM +0100, Gianfranco Costamagna wrote:
>>  -    fscanf(f, "%d", &num_bits);
>>  +    int fs = fscanf(f, "%d", &num_bits);
>>  +    if (EOF == fs) return ERR_NULL;
>>       key->bits = num_bits;
>>       len = size - sizeof(key->bits);
>>       for (i=0; i<len; i++) {
>>  -        fscanf(f, "%2x", &n);
>>  +        fs = fscanf(f, "%2x", &n);
>>           key->data[i] = n;
>>  +    if (EOF == fs) return ERR_NULL;
> 
> Shouldn't these check that fscanf's result is 1
> (e.g. change these to 'if (1 != fs)'?)

I partially agree.
The most appropriate solution should be 
if(1 != fs || EOF != fs)

> 
>>  -        fscanf(f, "%d %d %d %d\n", &xpos, &ypos, 
> &width, &height);
>>  +        if (! fscanf(f, "%d %d %d %d\n", &xpos, 
> &ypos, &width, &height)) {
>>  +        fprintf(stderr,"Coud not parse parameters for xpos, ypos, 
> width, height from glx_info file.\n");
>>  +    }
> 
> And here shouldn't the check be != 4?
Again
if(4 != fs || EOF != fs)

this way you check if the fscanf finished because of the EOF or not enough 
parameters read.

Right?
> 
> - Alyssa
> 
_______________________________________________
boinc_dev mailing list
[email protected]
http://lists.ssl.berkeley.edu/mailman/listinfo/boinc_dev
To unsubscribe, visit the above URL and
(near bottom of page) enter your email address.

Reply via email to