PRUNERS / FLiT

A project to quickly detect discrepancies in floating point computation across hardware, compilers, libraries and software.
Other
36 stars 6 forks source link

Error-prone use of `mkstemp()` and `mkdtemp()` in `fsutil.cpp` #293

Closed mikebentley15 closed 4 years ago

mikebentley15 commented 4 years ago

Bug Report

Describe the problem The calls to mkstemp() and mkdtemp() from within src/fsutil.cpp do not check the return values. These return values are essential to checks for error conditions. For example, if for some unknown reason mkstemp() fails to create a temporary file, we would not want to continue running as if it was created successfully.

Suggested Fix Check the return values for errors and if an error occurred, throw std::ios_base::failure exceptions.

I would like to create tests for this. Perhaps we would need to use Google Moc? I would like to learn how that works.

Alternative approaches: Hopefully the problem would be discovered elsewhere in the code. But would we want to risk it?

IanBriggs commented 4 years ago

I think we should check the status and throw the exception, but I'm not sure if we should add tests for this since it would require another external dependency (though only for testing).

mikebentley15 commented 4 years ago

Agreed. If we used Google Mock for this, then we would probably want to move all of our C++ tests to use Google Test (since they are now part of the same framework).

Also, I looked into Google Mock, and it would not help us with this problem unless we changed how we called the functions to begin with (through an interface class that can be used to override the behavior). I don't want to go through that. Perhaps we could do some link seams (see the third answer at https://stackoverflow.com/questions/2924440/advice-on-mocking-system-calls#2924607).