Merge pull request #8164 from jsquyres/pr/v4.1.x/keyval-parse-tweaks
v4.1.x: Keyval parse tweaks
Этот коммит содержится в:
Коммит
71ee907b0b
@ -12,6 +12,9 @@
|
|||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
* Copyright (c) 2015-2016 Los Alamos National Security, LLC. All rights
|
* Copyright (c) 2015-2016 Los Alamos National Security, LLC. All rights
|
||||||
* reserved.
|
* reserved.
|
||||||
|
* Copyright (c) 2018 Triad National Security, LLC. All rights
|
||||||
|
* reserved.
|
||||||
|
* Copyright (c) 2020 Cisco Systems, Inc. All rights reserved
|
||||||
* $COPYRIGHT$
|
* $COPYRIGHT$
|
||||||
*
|
*
|
||||||
* Additional copyrights may follow
|
* Additional copyrights may follow
|
||||||
@ -274,7 +277,7 @@ static int save_param_name (void)
|
|||||||
|
|
||||||
static int add_to_env_str(char *var, char *val)
|
static int add_to_env_str(char *var, char *val)
|
||||||
{
|
{
|
||||||
int sz, varsz, valsz, new_envsize;
|
int sz, varsz = 0, valsz = 0, new_envsize;
|
||||||
void *tmp;
|
void *tmp;
|
||||||
|
|
||||||
if (NULL == var) {
|
if (NULL == var) {
|
||||||
@ -284,22 +287,25 @@ static int add_to_env_str(char *var, char *val)
|
|||||||
varsz = strlen(var);
|
varsz = strlen(var);
|
||||||
if (NULL != val) {
|
if (NULL != val) {
|
||||||
valsz = strlen(val);
|
valsz = strlen(val);
|
||||||
/* account for '=' */
|
/* If we have a value, it will be preceeded by a '=', so be
|
||||||
|
sure to account for that */
|
||||||
valsz += 1;
|
valsz += 1;
|
||||||
}
|
}
|
||||||
sz = 0;
|
sz = 0;
|
||||||
if (NULL != env_str) {
|
if (NULL != env_str) {
|
||||||
sz = strlen(env_str);
|
sz = strlen(env_str);
|
||||||
/* account for ';' */
|
/* If we have a valid variable, the whole clause will be
|
||||||
|
terminated by a ';', so be sure to account for that */
|
||||||
sz += 1;
|
sz += 1;
|
||||||
}
|
}
|
||||||
/* add required new size incl NUL byte */
|
/* Sum the required new sizes, including space for a terminating
|
||||||
sz += varsz+valsz+1;
|
\0 byte */
|
||||||
|
sz += varsz + valsz + 1;
|
||||||
|
|
||||||
/* make sure we have sufficient space */
|
/* Make sure we have sufficient space */
|
||||||
new_envsize = envsize;
|
new_envsize = envsize;
|
||||||
while (new_envsize <= sz) {
|
while (new_envsize <= sz) {
|
||||||
new_envsize *=2;
|
new_envsize *= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NULL != env_str) {
|
if (NULL != env_str) {
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user