kernel/debug: Use strchrnul and memchr in parsing.

Slight efficiency improvement, and simplifies the code a bit too.

Change-Id: I502409a9aee260c3d0ad1c9003567e46c03b241b
Reviewed-on: https://review.haiku-os.org/c/haiku/+/10596
Reviewed-by: waddlesplash <[email protected]>
This commit is contained in:
Augustin Cavalier
2026-03-27 18:23:31 +00:00
committed by waddlesplash
parent 0ed6a7bdeb
commit 2b3a46cc1b
@@ -6,6 +6,7 @@
#include <safemode.h>
#define _DEFAULT_SOURCE
#include <ctype.h>
#include <string.h>
#include <strings.h>
@@ -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;