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

[Cpp] Challenge 2 (Unreviewed) #408

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

rbrtdambrosio
Copy link
Contributor

No description provided.

@CLAassistant
Copy link

CLAassistant commented Jan 16, 2017

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@jacktraf jacktraf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Getting the size of the array from the user is prone to error and could be dangerous in C, idk about C++. IMO it should determine the size of the array on its own

@rbrtdambrosio
Copy link
Contributor Author

@jacktraf Thanks for the comment :) I'm interested in this. Why is dangerous in C? I don't know C very well so I would like to understand more about it.

@jacktraf
Copy link
Contributor

Reading/writing past the end of a buffer/array in c/c++ is a big no no. Its classified as undefined behavior / buffer overflow (in the case of writing).
"In C the use of any automatic variable before it has been initialized yields undefined behavior, as does integer division by zero or indexing an array outside of its defined bounds (see buffer overflow)" https://en.m.wikipedia.org/wiki/Undefined_behavior

See also https://en.m.wikipedia.org/wiki/Buffer_overflow for possible security risks

@jacktraf
Copy link
Contributor

Also, never trust user input

@rbrtdambrosio
Copy link
Contributor Author

@jacktraf thanks for the answer :)
Yes i'm aware of the issues regarding the use of array beyond their end or without initialization.
I was only assuming a "legal" behavior from the user. If an integer value (in the int range) is used as array length there shouldn't be problem.
In any case it's an interesting point that I will keep in mind :)

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

Successfully merging this pull request may close these issues.

3 participants