From c588a291e61586c5b74e230919b490aab18d8290 Mon Sep 17 00:00:00 2001 From: 4rk <88458312+Dev-Tade@users.noreply.github.com> Date: Mon, 26 Feb 2024 06:22:06 -0300 Subject: [PATCH] Add very little sanitization to indentifier names in ExportDataAsCode() (#3832) --- src/utils.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/utils.c b/src/utils.c index 987021c73..78b3b7bdc 100644 --- a/src/utils.c +++ b/src/utils.c @@ -313,10 +313,16 @@ bool ExportDataAsCode(const unsigned char *data, int dataSize, const char *fileN byteCount += sprintf(txtData + byteCount, "// //\n"); byteCount += sprintf(txtData + byteCount, "////////////////////////////////////////////////////////////////////////////////////////\n\n"); - // Get file name from path and convert variable name to uppercase + // Get file name from path char varFileName[256] = { 0 }; strcpy(varFileName, GetFileNameWithoutExt(fileName)); - for (int i = 0; varFileName[i] != '\0'; i++) if ((varFileName[i] >= 'a') && (varFileName[i] <= 'z')) { varFileName[i] = varFileName[i] - 32; } + for (int i = 0; varFileName[i] != '\0'; i++) + { + // Convert variable name to uppercase + if ((varFileName[i] >= 'a') && (varFileName[i] <= 'z')) { varFileName[i] = varFileName[i] - 32; } + // Replace '-' (non valid character for C identifier with '_') + if (varFileName[i] == '-') { varFileName[i] = '_'; } + } byteCount += sprintf(txtData + byteCount, "#define %s_DATA_SIZE %i\n\n", varFileName, dataSize);