Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int ha_myisam::assign_to_keycache(THD* thd,
- HA_CHECK_OPT *check_opt)
- {
- ...
- const char *errmsg= 0;
- ...
- if ((error= mi_assign_to_key_cache(file, map, new_key_cache)))
- {
- char buf[STRING_BUFFER_USUAL_SIZE];
- my_snprintf(buf, sizeof(buf),
- "Failed to flush to index file (errno: %d)", error);
- errmsg = buf;
- error = HA_ADMIN_CORRUPT;
- }
- ...
- }
- It's not that simple with this code. Theoretically, the code contains an error. Practically, it works well.
- The V507 diagnostic message warns you that an object is used after being destroyed. The 'buf' buffer will be used after exiting the body of the 'if' operator.
- If 'buf' was an object of the class std::string, for instance, its behavior would be incorrect. We would use an already destroyed object in that case. But here 'buf' is an array created in the stack. The Visual C++ compiler doesn't use this stack area again, so the buffer will exist until the 'ha_myisam::assign_to_keycache' function finishes its work. Thus, no error occurs, although the code is potentially dangerous.
- This suspicious code was found in MySQL project by PVS-Studio static code analyzer.
- Warning message is:
- V507 Pointer to local array 'buf' is stored outside the scope of this array. Such a pointer will become invalid. myisam ha_myisam.cc 1156
- PVS-Studio is a static analyzer for detecting bugs in the source code of applications written in C, C++, C++11, C++/CX. Site: http://www.viva64.com/en/pvs-studio/
Advertisement
Add Comment
Please, Sign In to add comment