diff --git a/src/system/kernel/debug/safemode_settings.cpp b/src/system/kernel/debug/safemode_settings.cpp index c0a6ca6ebd..667f391deb 100644 --- a/src/system/kernel/debug/safemode_settings.cpp +++ b/src/system/kernel/debug/safemode_settings.cpp @@ -6,6 +6,7 @@ #include +#define _DEFAULT_SOURCE #include #include #include @@ -43,20 +44,21 @@ get_option_from_kernel_args(kernel_args* args, const char* settingsName, // Unfortunately we can't just use parse_driver_settings_string(), since // we might not have a working heap yet. So we do very limited parsing // ourselves. - const char* settingsEnd = settings + strlen(settings); int32 parameterLevel = 0; while (*settings != '\0') { // find end of line - const char* lineEnd = strchr(settings, '\n'); + const char* lineEnd = strchrnul(settings, '\n'); const char* nextLine; - if (lineEnd != NULL) + if (*lineEnd != '\0') nextLine = lineEnd + 1; else - nextLine = lineEnd = settingsEnd; + nextLine = lineEnd; // ignore any trailing comments - lineEnd = std::find(settings, lineEnd, '#'); + const char* commentStart = (const char*)memchr(settings, '#', lineEnd - settings); + if (commentStart != NULL) + lineEnd = commentStart; const char* nameStart = NULL; const char* nameEnd = NULL;