flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
cthug
You have a possible buffer overflow if you input 10 characters(because of the null termination), If not try debugging
![]() NOTE: most compilers warn about using gets as it is not safe, if you are using gcc, it prints a report of stack smashing if a buffer overflow occurs |
|||
![]() |
|
Tyler
It's not printf, it's scanf. scanf leaves the (cr)lf in the input buffer, which gets then reads, causing gets to terminate. Use scanf or don't use scanf, you just can't mix it with other stdin function because of it leaving the \n on the buffer and causing you problems.
cthug wrote:
Neither is scanf, or most other commonly used libc input methods. Use fread because it allows you to specify the length of your buffer. |
|||
![]() |
|
baldr
Tyler,
scanf() works as specified. If programmer wants to skip the rest of input line, he should do this explicitly: "5Hello!\n" is valid input for the original program (almost overflows buffer, though). scanf() is unsafe in the same sense as gets(): if you haven't specified field width, it's your problem, not libc; scanf() provides facility to do so, thus it's safer. ![]() ----8<---- sleepsleep, Tyler's right, gets() should be banished. fgets(), probably? |
|||
![]() |
|
vid
Something might need to be added. Whenever scanf finds blank characters in format string, it skips all blank characters (including EOLs) on the input.
|
|||
![]() |
|
baldr
vid,
while (!feof(stdin) && '\n'!=getc(stdin)); before gets() does it. |
|||
![]() |
|
vid
baldr wrote: vid, How so? You mean won't be shown properly in case when both stdin and stdout point to same interactive console? Or what? Quote: and aa can't have leading whitespace; why not " %d " then? (Of course, this eats blank lines, so it may not be desired in some cases) Quote:
I didn't know about this. Is this standard C, or GNU extension? while (!feof(stdin) && '\n'!=getc(stdin)); before gets() does it.[/quote] |
|||
![]() |
|
baldr
vid,
I mean "AA : " prompt won't be shown until you enter both n and aa values. vid wrote: I didn't know about this. Is this standard C, or GNU extension? fgets() / sscanf seems to be proper solution: first shows that program expects entire lines as input, second parses them. |
|||
![]() |
|
revolution
Just roll your own proc. Problem solved.
|
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.