On Aug 5, 2012, at 11:19 PM, Mike Frysinger wrote:
> so %n is telling us how many *bytes* were read, not the number of elements 
> consumed.

Yes, but the *return value* is the "the number of input *items* assigned" (man 
sscanf); that's why I check that it's equal to 2 indicating that parsing didn't 
fail before reaching %n:

>  if (sscanf(eq, "%lu%n", lu, &dummy) == 2)


>       sscanf("0a", "%lu%n", lu, &dummy);
> - return value = 1

and 1!=2

Perhaps a clearer alternative would be:

  if (sscanf(eq, "%lu%c", lu, &dummy) == 1)

If there is junk left over the %c will match and it will return 2, and 2!=1.

For the record I am not a huge fan of the libc parsing/printing functions.  
It's been at least five years since I last used them in code I wrote myself.  
If you have a better way to check that the input was fully consumed, that's 
fine with me.


> however, i'd point out that this only catches errors where the user supplied 
> a 
> hex value that contains non-numbers.

Yes, and that's the only situation where the user -- such as me -- is thinking 
to themselves "well, I gave it something with letters in it, and it didn't 
complain, so it can't possibly be parsing it as decimal or octal!"

Seriously, this is the reason why I never bothered trying a "0x" or "16'h" 
prefix.


> maybe as part of the cable output, we can echo back "forcing VID=0x1234" so 
> that they can immediately tell "oh, my number is being interpreted as a 
> decimal when i really want hex, so i need to add the 0x prefix".

That would be fine too.

  - e


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
UrJTAG-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/urjtag-development

Reply via email to