Hi David,
I saw the commit, credist should go to Steffen not to me
BTW
index b34f4d7..d1a0e1b 100644 (file)
--- a/lib/crypt.cpp
+++ b/lib/crypt.cpp
@@ -208,14 +208,17 @@ int scan_key_hex(FILE* f, KEY* key, int size) {
}
if (j != len) return ERR_NULL;
#else
- fscanf(f, "%d", &num_bits);
+ int fs = fscanf(f, "%d", &num_bits);
+ if (fs != 1) 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);
+ if (fs != 1) return ERR_NULL;
key->data[i] = n;
}
- fscanf(f, ".");
+ fs = fscanf(f, ".");
+ if (fs == EOF) return ERR_NULL;
#endif
return 0;
}
is better to check if fs != 0
+ if (fs == EOF) return ERR_NULL;
I wrote a simple code, that returns 0 if successful and -1 otherwise
bests
G.
----- Messaggio originale -----
> Da: Alyssa Milburn <[email protected]>
> A: Gianfranco Costamagna <[email protected]>
> Cc: "[email protected]" <[email protected]>;
> "[email protected]" <[email protected]>
> Inviato: Martedì 9 Luglio 2013 11:43
> Oggetto: Re: [boinc_dev] addressing some clang warnings
>
> On Tue, Jul 09, 2013 at 08:25:24AM +0100, Gianfranco Costamagna wrote:
>> >> - 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)
>
> That's equivalent to 'if(true)' because fs can't be both 1 and
> EOF,
> so either (1 != fs) or (EOF != fs) is true.
>
> I think you want an error whenever it is *not* 1, so you just want the
> (1 != fs): whether it is 0 (failed match) or EOF (ran out of input),
> you want it to error out.
>
> - 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.