Avoid VLA usage and prohibit it by compiler flag

This commit is contained in:
sfan5 2024-10-27 20:41:25 +01:00
parent 721e06451e
commit 38f4d11d53
4 changed files with 6 additions and 7 deletions

View file

@ -855,8 +855,7 @@ if(MSVC)
endif() endif()
else() else()
# GCC or compatible compilers such as Clang # GCC or compatible compilers such as Clang
set(WARNING_FLAGS "-Wall -Wextra") set(WARNING_FLAGS "-Wall -Wextra -Wno-unused-parameter -Werror=vla")
set(WARNING_FLAGS "${WARNING_FLAGS} -Wno-unused-parameter")
if(WARN_ALL) if(WARN_ALL)
set(RELEASE_WARNING_FLAGS "${WARNING_FLAGS}") set(RELEASE_WARNING_FLAGS "${WARNING_FLAGS}")
else() else()

View file

@ -291,13 +291,13 @@ bool GUIModalMenu::preprocessEvent(const SEvent &event)
s32 selected_idx = dropdown->getSelected(); s32 selected_idx = dropdown->getSelected();
s32 option_size = dropdown->getItemCount(); s32 option_size = dropdown->getItemCount();
std::string list_of_options[option_size]; std::vector<std::string> list_of_options;
for (s32 i = 0; i < option_size; i++) { for (s32 i = 0; i < option_size; i++) {
list_of_options[i] = wide_to_utf8(dropdown->getItem(i)); list_of_options.push_back(wide_to_utf8(dropdown->getItem(i)));
} }
porting::showComboBoxDialog(list_of_options, option_size, selected_idx); porting::showComboBoxDialog(list_of_options.data(), option_size, selected_idx);
return true; // Prevent the Irrlicht dropdown from opening. return true; // Prevent the Irrlicht dropdown from opening.
} }
} }

View file

@ -142,7 +142,7 @@ void showTextInputDialog(const std::string &hint, const std::string &current, in
jhint, jcurrent, jeditType); jhint, jcurrent, jeditType);
} }
void showComboBoxDialog(const std::string optionList[], s32 listSize, s32 selectedIdx) void showComboBoxDialog(const std::string *optionList, s32 listSize, s32 selectedIdx)
{ {
jmethodID showdialog = jnienv->GetMethodID(activityClass, "showSelectionInputDialog", jmethodID showdialog = jnienv->GetMethodID(activityClass, "showSelectionInputDialog",
"([Ljava/lang/String;I)V"); "([Ljava/lang/String;I)V");

View file

@ -27,7 +27,7 @@ void showTextInputDialog(const std::string &hint, const std::string &current, in
* @param listSize Size of the list * @param listSize Size of the list
* @param selectedIdx Selected index * @param selectedIdx Selected index
*/ */
void showComboBoxDialog(const std::string optionList[], s32 listSize, s32 selectedIdx); void showComboBoxDialog(const std::string *optionList, s32 listSize, s32 selectedIdx);
/** /**
* Opens a share intent to the file at path * Opens a share intent to the file at path