On Wed, Jun 30, 2010 at 09:35:49PM +0200, Marek Lindner wrote:
On Wednesday 30 June 2010 20:03:13 Linus Lüssing wrote:
- char msecs_buff[4];
- memset(msecs_buff, '0', sizeof(msecs_buff));
- msecs_buff[3] = '\0';
Shouldn't a simple memset(msecs_buff, 0, sizeof(msecs_buff)); be enough ?
The intention of the msecs_buff was, to do some zeroed alignment which is not possible with sscanf automatically (so without it, a -t 0.99 were converted to 99ms instead of 990). The last one is is for just marking the end of the string (note, '0' != '\0' ;) ).
if (sscanf(optarg, "%3d.%3s", &orig_timeout_secs,
else if (sscanf(optarg, "%3d", &orig_timeout_secs) == 1) { ; }
else {
I don't quite understand the sense of the "else if" here. You could also write: else if (sscanf(optarg, "%3d", &orig_timeout_secs) != 1)
Yep, you're right, I guess I was thinking too 'imperative' here :D.
and write no else block but I don't see why 1 second should be accepted and nothing else ?
Nope, sscanf returns the number of succesfully scanned values, so the 1 is not actually 1sec. But you're right, it can't read more than 1 with only one %d in it anyway, so checking sscanf() < 1 would be fine too.
Anyway, I guess you're right, that integer arithmetics was pretty much like using a slegdehammer to crack a nut in this case :).
See new patches for a less 'creative' approach :P.
Regards, Marek
Cheers, Linus