Project Name | CID | Checker | Category | Developer Description |
---|---|---|---|---|
LiquidityC/flat | 1375004 | RETURN_LOCAL | Memory - illegal accesses | This was the kind of error that most likely would never cause a problem during development but could have wreaked havoc after a release. It would have been terrible to find the problem if it was ever reported by a user. Memory corruption errors are never easy to find unless they become obvious during implementation. |
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
{ freeTexture(); SDL_Surface* imgSurface = TTF_RenderText_Solid(font, text.c_str(), color); if (imgSurface == nullptr) { std::cerr << "Failed to load text image: " << TTF_GetError() << std::endl; return false; } texture = SDL_CreateTextureFromSurface(renderer, imgSurface); if (texture == nullptr) { std::cerr << "Unable to create text texture: " << SDL_GetError() << std::endl; } this->w = imgSurface->w; this->h = imgSurface->h; SDL_FreeSurface(imgSurface); return texture != nullptr; } void Texture::render(SDL_Renderer *renderer, const SDL_Rect* clip, const SDL_Rect* pos) const { |
< 1. Condition "this->texture == NULL", taking false branch.
85 86 87 |
if (texture == nullptr) { return; } |
< 2. Condition "pos == NULL", taking true branch.
89 90 |
if (pos == nullptr) {
SDL_Rect box = { x, y, w, h }; |
<< 3. Assigning: "pos" = "&box" (address of local variable "box").
91 |
pos = &box; |
<< 4. Variable "box" goes out of scope.
92 |
} |
<<< CID 1375004: Memory - illegal accesses RETURN_LOCAL <<< 5. Using "pos", which points to an out-of-scope variable "box".
94 95 96 |
SDL_RenderCopy(renderer, texture, clip, pos);
}
} // namespace flat2d |
3. local_ptr_assign_local | Texture.cpp:91 | |
4. out_of_scope | Texture.cpp:92 | |
5. use_invalid | Texture.cpp:94 |