We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi,
I have one question about Cortexm3 from smartfusion device from actel. Could you pls help me? I add follwing codes into retarget.c and then add retarget.c into source code group and find : printf function works.however scanf function doesn't. anybody knows why?
int fputc(int ch, FILE *f) { return ((int)ITM_SendChar(ch)); } int fgetc(FILE *f) { int i=0; i=ITM_ReceiveChar(); if((-1)!=i) return ((int)ITM_SendChar((uint32_t)i)); else return (0); }
printf("hello world\n\r"); // when executed, string displayed in debug(printf)window scanf("%s",str); // when executed, hard fault occurs
Well known dangerous functions that stands for a large number of buffer overflows in this world includes: scanf() gets() sprintf() strcpy()
Note that Keil doesn't have the standard gets() but have duplicated the fix from fgets(), i.e. added a size parameter telling the max number of characters that may be handled.