mupen64plus / mupen64plus-video-glide64mk2

Video plugin for Mupen64Plus 2.0 based on 10th anniversary release code from gonetz
28 stars 37 forks source link

Remove MAX_NUMCORE. #99

Closed bugfood closed 6 years ago

bugfood commented 6 years ago

This fixes a bug I hit in TxQuantize.cpp: the params array is initialized with length MAX_NUMCORE, but accessed at positions up to numcore-1. The numcore variable is not constrained to MAX_NUMCORE, so on systems with cores greater than MAX_NUMCORE, there can be a segfault.

Is there any downside? I don't see one; I'm not familiar with the code, but it looks like this may cause a negligible decrease in memory usage on systems with less than MAX_NUMCORE (8) cores, and negligibly higher memory usage on systems with a higher number of cores as the price of not segfaulting.

I do not know if I have exercised all code paths in testing this change, but the usage of MAX_NUMCORE seems the same in all cases.

richard42 commented 6 years ago

the only potential downside I see here is that the dynamic array allocation on the stack (local variable) is a C99 feature which may not be supported on all compilers. Hopefully MSVC 2013 has this; I'll merge it for now and fix it later if it causes problems for our windows build.

bugfood commented 6 years ago

Thanks.

If you would later like me to rework it using malloc/free, then let me know. I would at that point ask if you had any desire for me to use a macro for the initialization in order to reduce adding duplicate lines.