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

C++ code health suggestions #29

Open
ZLLentz opened this issue Jan 15, 2025 · 0 comments
Open

C++ code health suggestions #29

ZLLentz opened this issue Jan 15, 2025 · 0 comments

Comments

@ZLLentz
Copy link
Member

ZLLentz commented Jan 15, 2025

From #22 (review)

I like your solutions. in addition I have suggestions that I think it will limit segfualt problems:

using -fsanitize compile flag to make it easier to detect such problems
replace c-style arrays with std::array with exception handling

From #22 (comment)

This is minor but if using a modern C++ approach I think a smart pointer is considered best practice. Raw pointers should be used only when performance/memory management are critical.

If only one pointer for ImageBuffer is needed, std::unique_ptr would work.

#include

int _max_row(unique_ptr imageBuffer, long count)
{
if (imageBuffer->imgwidth > 0) {
return std::min(imageBuffer->imgheight, (int) std::floor(count / imageBuffer->imgwidth));
} else {
return 0;
}
}
Regarding the buffer overflow problem--if the program uses std::vector, std::array or other dynamically sized containers similar to a python list maybe this issue can be avoided. Raw arrays is probably one of the major reasons the world moved away from C.

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

No branches or pull requests

1 participant