-
Notifications
You must be signed in to change notification settings - Fork 3
Evil: Add evil_stdlib_mkstemp_create_many test case #393
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
base: devs/expertise/native-windows
Are you sure you want to change the base?
Evil: Add evil_stdlib_mkstemp_create_many test case #393
Conversation
|
|
||
| EFL_START_TEST(evil_stdlib_mkstemp_create_many) | ||
| { | ||
| const unsigned long long files_to_create = 1000; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why 1000?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First I thought to create as many files as possible, trying to reach the posix limit, but that is completely nonsense: it will take forever to finish, possibly reaching timeout.
Than I put some arbitrary quantity to be described as 'many'. 🙅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
welp...probably there are few cases where people create as many as 1k temporary files, sooooo, fair enough
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it should be dynamically allocated?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, any specific reason for unsigned long long in such a short value (1000)? If it is to conform with array length type, just use a straight forward size_t.
6ad1a58 to
efc1a5a
Compare
| unsigned long long files_created; | ||
| char templates[files_to_create][template_len]; | ||
| int fds[files_to_create] = { NULL }; | ||
| // Create temporary files | ||
| for (files_created = 0; files_created < files_to_create; files_created++) | ||
| { | ||
| strncpy_s(templates[files_created], template_len, template, template_len); | ||
|
|
||
| fds[files_created] = mkstemp(templates[files_created]); | ||
| fail_if(fds[files_created] < 0); | ||
| } | ||
|
|
||
| // Close temporary files | ||
| for (files_created = 0; files_created < files_to_create; files_created++) | ||
| fail_if(close(fds[files_created]) == -1); | ||
|
|
||
| // Remove temporary files | ||
| for (files_created = 0; files_created < files_to_create; files_created++) | ||
| fail_if(unlink(templates[files_created]) == -1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Careful: this (declare without value to use inside one or multiple for-loops) is intensely error-prone (from accidental usage of unitialized value to accidental usage of an unexpected value that was given in a previous loop). I really would appreciate if it was used and declared in-loop:
| unsigned long long files_created; | |
| char templates[files_to_create][template_len]; | |
| int fds[files_to_create] = { NULL }; | |
| // Create temporary files | |
| for (files_created = 0; files_created < files_to_create; files_created++) | |
| { | |
| strncpy_s(templates[files_created], template_len, template, template_len); | |
| fds[files_created] = mkstemp(templates[files_created]); | |
| fail_if(fds[files_created] < 0); | |
| } | |
| // Close temporary files | |
| for (files_created = 0; files_created < files_to_create; files_created++) | |
| fail_if(close(fds[files_created]) == -1); | |
| // Remove temporary files | |
| for (files_created = 0; files_created < files_to_create; files_created++) | |
| fail_if(unlink(templates[files_created]) == -1); | |
| char templates[files_to_create][template_len]; | |
| int fds[files_to_create] = { NULL }; | |
| // Create temporary files | |
| for (size_t files_created = 0; files_created < files_to_create; files_created++) | |
| { | |
| strncpy_s(templates[files_created], template_len, template, template_len); | |
| fds[files_created] = mkstemp(templates[files_created]); | |
| fail_if(fds[files_created] < 0); | |
| } | |
| // Close temporary files | |
| for (size_t files_created = 0; files_created < files_to_create; files_created++) | |
| fail_if(close(fds[files_created]) == -1); | |
| // Remove temporary files | |
| for (size_t files_created = 0; files_created < files_to_create; files_created++) | |
| fail_if(unlink(templates[files_created]) == -1); |
You don't have to worry about allocating multiple variables, since what will happen is that the compiler will reuse the same register for them, plus having additional guarantees over the expected variable initialization/value.
While investigating temporary file creation from evil I noticed that there are no tests to check if the implementation of mkstemp can create several files in sequence.
At the time I need to check that, than I wrote this simple test.
Maybe it worth to add in our current branch, what do you think?