Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

separate threads for read and display #5

Closed
tenox7 opened this issue Oct 14, 2018 · 3 comments
Closed

separate threads for read and display #5

tenox7 opened this issue Oct 14, 2018 · 3 comments

Comments

@tenox7
Copy link
Owner

tenox7 commented Oct 14, 2018

scanf should go to separate thread so it doesn't block the display completely

@spacerace
Copy link

I know scanf makes things much more comfortable, but in times of any possible input to a program it should be noted, that scanf is a very insecure funktion, resp. people are using it very insecure in a lot of cases.
Very common problems are:

  • too long input: example: scanf("%20c") takes max up to 20 characters, then stops.
  • scanf will write over an array's boundaries, almost no one makes sure it doesn't.
  • In the end, if there is not enough space, the string gets truncated but does not end with '\0'. A "str[strlen(str)] = '\0';" after every call to scanf makes sure there are no unterminated strings.
  • truncation can't be detected without comparing the input data to output data. ("open end problem").

For parsing data I rather suggest the classic string functions. Also strlcpy/strlcat from BSD are known to produce terminated strings. Makes things much more comfortable.
The classic functions like strcmp, sprintf, ... also may be considered bad, because of no length limit. There are also strncmp, snprintf, strncat/ncpy (which provides no termination), ...

With these classics you also have to deal with lengths/termination, but in "smaller steps", so one may see mistakes more easily.

In general scanf and gets are making my hair stand off from my arms. This is no critisizm, this is just a suggestion to think about. scanf may indeed be used securely, but it is very common to introduce memory-leaks or other problems...

@tenox7
Copy link
Owner Author

tenox7 commented Oct 17, 2018

While your claims are generally correct they are also very broad and I'm not sure if they are applicable to this specific use case. I would suggest that you look at scanf usage in ttyplot and refine your comment to be much more specific. Ideally please send a PR with suggested changes.

@tenox7
Copy link
Owner Author

tenox7 commented Apr 2, 2019

not needed

@tenox7 tenox7 closed this as completed Apr 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants