Re: XForms: problems with fl_get_choice_text

Steve Lamont (
Thu, 6 Nov 97 06:53:03 PST

To subscribers of the xforms list from (Steve Lamont) :

> Thanks for the idea, but this should be no problem.
> To give some identifiers:
> sscanf((char *)datum(),"%*s %s %d %s %d",monat,&tag,time_string,&jahr);
> int tag;
> char monat[6];
> int jahr;
> char *time_string;
> /* (tag=day, monat=month, jahr=year)
> datum() returns something like "Thu Nov 6 11:12:34 1997"
> and the sscanf should get the things into the different variables
> %*s omits the first (Thu)
> %s writes "Nov" into monat (=char monat[6])
> %d writes 6 into tag
> %s writes "11:12:34" into time_string
> %d writes 1997 into jahr
> Ok, that's it. I think that should work, or did I misinterpret something?


Is the pointer `time_string' initialized? If not, you're going to be
writing into who knows where. sscanf() does not do any memory
allocation, it simply returns data to where ever it thinks it's told
to write. If `time_string' isn't initialized, then it will have
whatever value just happens to be on the stack in that slot.

You should change your code to read

char *time_string;


time_string = ( char *) malloc( TIME_STRING_SIZE );


sscanf( ... );

where TIME_STRING_SIZE is whatever size is appropriate -- maybe 9?


char time_string[TIME_STRING_SIZE];

I expect this is the reason why your pointer is getting trampled.


To unsubscribe, send the message "unsubscribe" to or see
Xforms Home Page:
List Archive: