xkb: maprules: fix potential NULL pointer dereference warnings

Even though the cases might be hypothetical, it's still better having some
tiny extra checks (that might be even optimized-out) and reduce the analyzer
noise a bit.

Signed-off-by: Enrico Weigelt, metux IT consult <info@metux.net>
This commit is contained in:
Enrico Weigelt, metux IT consult 2025-05-06 16:53:09 +02:00
parent 427400fcc0
commit 269cd0f8ac

View File

@ -93,7 +93,9 @@ InputLineAddChar(InputLine * line, int ch)
{
if (line->num_line >= line->sz_line) {
if (line->line == line->buf) {
line->line = xallocarray(line->sz_line, 2);
line->line = calloc(line->sz_line, 2);
if (line->line == NULL)
return -1;
memcpy(line->line, line->buf, line->sz_line);
}
else {
@ -379,7 +381,7 @@ CheckLine(InputLine * line,
_Xstrtokparams strtok_buf;
Bool append = FALSE;
if (line->line[0] == '!') {
if (line && line->line && line->line[0] == '!') {
if (line->line[1] == '$' ||
(line->line[1] == ' ' && line->line[2] == '$')) {
char *gname = strchr(line->line, '$');