diff options
author | Marek BehĂșn <marek.behun@nic.cz> | 2021-10-17 18:36:36 +0300 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2021-10-21 21:50:48 +0300 |
commit | a473766cce44882237e567bcd58f7559ecdd0440 (patch) | |
tree | 17e9fe102e3c356888568acfa17613c5d740a4fe /cmd | |
parent | 3112ce0ce8195880aec5e9373434a85e21c3e1af (diff) | |
download | u-boot-a473766cce44882237e567bcd58f7559ecdd0440.tar.xz |
env: Use memcpy() instead of ad-hoc code to copy variable value
Copy the value of the found variable into given buffer with memcpy()
instead of ad-hoc code.
Signed-off-by: Marek BehĂșn <marek.behun@nic.cz>
Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/nvedit.c | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/cmd/nvedit.c b/cmd/nvedit.c index 527b522e9e..ffcfb55f10 100644 --- a/cmd/nvedit.c +++ b/cmd/nvedit.c @@ -735,7 +735,7 @@ int env_get_f(const char *name, char *buf, unsigned len) for (p = env; *p != '\0'; p = end + 1) { const char *value; - int n, res; + unsigned res; for (end = p; *end != '\0'; ++end) if (end - env >= CONFIG_ENV_SIZE) @@ -746,20 +746,14 @@ int env_get_f(const char *name, char *buf, unsigned len) continue; res = end - value; + memcpy(buf, value, min(len, res + 1)); - /* found; copy out */ - for (n = 0; n < len; ++n, ++buf) { - *buf = *value++; - if (*buf == '\0') - return res; + if (len <= res) { + buf[len - 1] = '\0'; + printf("env_buf [%u bytes] too small for value of \"%s\"\n", + len, name); } - if (n) - *--buf = '\0'; - - printf("env_buf [%u bytes] too small for value of \"%s\"\n", - len, name); - return res; } |