I have a list of numbers and want to give my users the opportunity to enter a printf style format string to indicate how numbers should be displayed.
How can I check the user entered format string in the parameter list? Incorrect input should not cause the program to crash, and I want to avoid any string type attacks.
I don't care if validation processes only the format parameters specified in POSIX or a specific compiler supercomplex. Is there any library call to do this, or should I write it myself?
Clarification:
I need something like this:
float var1, var2, var3, var4;
const char * userSupplied = getFormatStringFromUser();
if( isValidFormat( userSupplied, "float", "float", "float", "float" ) )
printf( userSupplied, var1, var2, var3, var4 );
else
printf( "The format you gave was invalid!\n" );
, .
, .
, isValidFormat():
- "% f% g% e%.1f"
- "Foo -% g, Bar -% g"
- ""
: