mirror of
https://git.openafs.org/openafs.git
synced 2025-01-19 07:20:11 +00:00
Satisfy clang's aggressive strlcpy warnings
Passing something related to the length of the source as the length argument to strlcpy triggers a warning, which is converted to an error with --enable-checking (on FreeBSD 10.0). The current code is safe, since it is using the same expression that was used to allocate the destination buffer, but switch to using a separate variable to hold the length and use that variable for both allocation and copying, to appease the compiler. Change-Id: I580083d142fd19a4e7828c915b4846868fa8f917 Reviewed-on: http://gerrit.openafs.org/10818 Tested-by: BuildBot <buildbot@rampaginggeek.com> Reviewed-by: Perry Ruiter <pruiter@sinenomine.net> Reviewed-by: Jeffrey Altman <jaltman@your-file-system.com>
This commit is contained in:
parent
add4b8100e
commit
a52346ae50
@ -1382,6 +1382,7 @@ cmd_OptionAsList(struct cmd_syndesc *syn, int pos, struct cmd_item **value)
|
|||||||
const char *str;
|
const char *str;
|
||||||
struct cmd_item *item, **last;
|
struct cmd_item *item, **last;
|
||||||
const char *start, *end;
|
const char *start, *end;
|
||||||
|
size_t len;
|
||||||
int code;
|
int code;
|
||||||
|
|
||||||
if (pos > syn->nParms)
|
if (pos > syn->nParms)
|
||||||
@ -1406,8 +1407,9 @@ cmd_OptionAsList(struct cmd_syndesc *syn, int pos, struct cmd_item **value)
|
|||||||
start = str;
|
start = str;
|
||||||
while ((end = strchr(start, ' '))) {
|
while ((end = strchr(start, ' '))) {
|
||||||
item = calloc(1, sizeof(struct cmd_item));
|
item = calloc(1, sizeof(struct cmd_item));
|
||||||
item->data = malloc(end - start + 1);
|
len = end - start + 1;
|
||||||
strlcpy(item->data, start, end - start + 1);
|
item->data = malloc(len);
|
||||||
|
strlcpy(item->data, start, len);
|
||||||
*last = item;
|
*last = item;
|
||||||
last = &item->next;
|
last = &item->next;
|
||||||
for (start = end; *start == ' '; start++); /* skip any whitespace */
|
for (start = end; *start == ' '; start++); /* skip any whitespace */
|
||||||
@ -1416,8 +1418,9 @@ cmd_OptionAsList(struct cmd_syndesc *syn, int pos, struct cmd_item **value)
|
|||||||
/* Catch the final element */
|
/* Catch the final element */
|
||||||
if (*start != '\0') {
|
if (*start != '\0') {
|
||||||
item = calloc(1, sizeof(struct cmd_item));
|
item = calloc(1, sizeof(struct cmd_item));
|
||||||
item->data = malloc(strlen(start) + 1);
|
len = strlen(start) + 1;
|
||||||
strlcpy(item->data, start, strlen(start) + 1);
|
item->data = malloc(len);
|
||||||
|
strlcpy(item->data, start, len);
|
||||||
*last = item;
|
*last = item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user