lint: don't call memcpy with null pointer
Even copying 0 bytes from a null pointer invokes undefined behavior.
This commit is contained in:
parent
922b235ff9
commit
88d3a49009
|
@ -1,5 +1,5 @@
|
|||
%{
|
||||
/* $NetBSD: cgram.y,v 1.502 2024/05/12 08:48:36 rillig Exp $ */
|
||||
/* $NetBSD: cgram.y,v 1.503 2024/05/12 09:07:41 rillig Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
|
||||
|
@ -35,7 +35,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID)
|
||||
__RCSID("$NetBSD: cgram.y,v 1.502 2024/05/12 08:48:36 rillig Exp $");
|
||||
__RCSID("$NetBSD: cgram.y,v 1.503 2024/05/12 09:07:41 rillig Exp $");
|
||||
#endif
|
||||
|
||||
#include <limits.h>
|
||||
|
@ -118,9 +118,10 @@ attribute_list_add(attribute_list *list, attribute attr)
|
|||
attribute *old_attrs = list->attrs;
|
||||
list->cap = 16 + 2 * list->cap;
|
||||
list->attrs = block_zero_alloc(
|
||||
list->cap * sizeof(*list->attrs), "attribute_list.attrs");
|
||||
memcpy(list->attrs, old_attrs,
|
||||
list->len * sizeof(*list->attrs));
|
||||
list->cap * sizeof(*list->attrs), "attribute[]");
|
||||
if (list->len > 0)
|
||||
memcpy(list->attrs, old_attrs,
|
||||
list->len * sizeof(*list->attrs));
|
||||
}
|
||||
list->attrs[list->len++] = attr;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: lex.c,v 1.226 2024/05/12 08:48:36 rillig Exp $ */
|
||||
/* $NetBSD: lex.c,v 1.227 2024/05/12 09:07:41 rillig Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
|
||||
|
@ -38,7 +38,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID)
|
||||
__RCSID("$NetBSD: lex.c,v 1.226 2024/05/12 08:48:36 rillig Exp $");
|
||||
__RCSID("$NetBSD: lex.c,v 1.227 2024/05/12 09:07:41 rillig Exp $");
|
||||
#endif
|
||||
|
||||
#include <ctype.h>
|
||||
|
@ -1545,9 +1545,10 @@ seq_reserve(balanced_token_sequence *seq)
|
|||
seq->cap = 16 + 2 * seq->cap;
|
||||
const balanced_token *old_tokens = seq->tokens;
|
||||
balanced_token *new_tokens = block_zero_alloc(
|
||||
seq->cap * sizeof(*seq->tokens), "balanced_tokens");
|
||||
memcpy(new_tokens, old_tokens,
|
||||
seq->len * sizeof(*seq->tokens));
|
||||
seq->cap * sizeof(*seq->tokens), "balanced_token[]");
|
||||
if (seq->len > 0)
|
||||
memcpy(new_tokens, old_tokens,
|
||||
seq->len * sizeof(*seq->tokens));
|
||||
seq->tokens = new_tokens;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: tree.c,v 1.642 2024/05/11 15:53:38 rillig Exp $ */
|
||||
/* $NetBSD: tree.c,v 1.643 2024/05/12 09:07:41 rillig Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1994, 1995 Jochen Pohl
|
||||
|
@ -37,7 +37,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__RCSID)
|
||||
__RCSID("$NetBSD: tree.c,v 1.642 2024/05/11 15:53:38 rillig Exp $");
|
||||
__RCSID("$NetBSD: tree.c,v 1.643 2024/05/12 09:07:41 rillig Exp $");
|
||||
#endif
|
||||
|
||||
#include <float.h>
|
||||
|
@ -4214,10 +4214,10 @@ add_function_argument(function_call *call, tnode_t *arg)
|
|||
if (call->args_len >= call->args_cap) {
|
||||
call->args_cap += 8;
|
||||
tnode_t **new_args = expr_zero_alloc(
|
||||
call->args_cap * sizeof(*call->args),
|
||||
"function_call.args");
|
||||
memcpy(new_args, call->args,
|
||||
call->args_len * sizeof(*call->args));
|
||||
call->args_cap * sizeof(*call->args), "tnode*[]");
|
||||
if (call->args_len > 0)
|
||||
memcpy(new_args, call->args,
|
||||
call->args_len * sizeof(*call->args));
|
||||
call->args = new_args;
|
||||
}
|
||||
call->args[call->args_len++] = arg;
|
||||
|
|
Loading…
Reference in New Issue