[U-Boot] [PATCH v2] tools: env: support skip leading zero of env
Stefan Agner
stefan.agner at toradex.com
Tue Nov 27 13:48:47 UTC 2018
Maybe I miss something, but why is this needed exactly?
--
Stefan
On 27.11.18 02:49, zqb-all wrote:
> Signed-off-by: zqb-all <zhuangqiubin at gmail.com>
> ---
> v2: fix all "env = environment.data" and "env = default_environment"
>
> tools/env/fw_env.c | 46 ++++++++++++++++++++++++++++++++++++++++------
> 1 file changed, 40 insertions(+), 6 deletions(-)
>
> diff --git a/tools/env/fw_env.c b/tools/env/fw_env.c
> index a5d7595..60742b6 100644
> --- a/tools/env/fw_env.c
> +++ b/tools/env/fw_env.c
> @@ -398,7 +398,14 @@ char *fw_getenv(char *name)
> {
> char *env, *nxt;
>
> - for (env = environment.data; *env; env = nxt + 1) {
> + for (nxt = environment.data; !(*nxt); ++nxt) {
> + if (nxt >= &environment.data[ENV_SIZE]) {
> + fprintf (stderr, "## Error: "
> + "environment is empty\n");
> + return NULL;
> + }
> + }
> + for (env = nxt; *env; env = nxt + 1) {
> char *val;
>
> for (nxt = env; *nxt; ++nxt) {
> @@ -423,8 +430,14 @@ char *fw_getenv(char *name)
> char *fw_getdefenv(char *name)
> {
> char *env, *nxt;
> -
> - for (env = default_environment; *env; env = nxt + 1) {
> + for (nxt = default_environment; !(*nxt); ++nxt) {
> + if (nxt >= &default_environment[ENV_SIZE]) {
> + fprintf (stderr, "## Error: "
> + "default environment is empty\n");
> + return NULL;
> + }
> + }
> + for (env = nxt; *env; env = nxt + 1) {
> char *val;
>
> for (nxt = env; *nxt; ++nxt) {
> @@ -464,7 +477,14 @@ int fw_printenv(int argc, char *argv[], int value_only, struct env_opts *opts)
>
> if (argc == 0) { /* Print all env variables */
> char *env, *nxt;
> - for (env = environment.data; *env; env = nxt + 1) {
> + for (nxt = environment.data; !(*nxt); ++nxt) {
> + if (nxt >= &environment.data[ENV_SIZE]) {
> + fprintf (stderr, "## Error: "
> + "environment is empty\n");
> + return -1;
> + }
> + }
> + for (env = nxt; *env; env = nxt + 1) {
> for (nxt = env; *nxt; ++nxt) {
> if (nxt >= &environment.data[ENV_SIZE]) {
> fprintf(stderr, "## Error: "
> @@ -537,7 +557,14 @@ int fw_env_write(char *name, char *value)
> /*
> * search if variable with this name already exists
> */
> - for (nxt = env = environment.data; *env; env = nxt + 1) {
> + for (nxt = environment.data; !(*nxt); ++nxt) {
> + if (nxt >= &environment.data[ENV_SIZE]) {
> + fprintf (stderr, "## Error: "
> + "environment is empty\n");
> + return -1;
> + }
> + }
> + for (env = nxt; *env; env = nxt + 1) {
> for (nxt = env; *nxt; ++nxt) {
> if (nxt >= &environment.data[ENV_SIZE]) {
> fprintf(stderr, "## Error: "
> @@ -614,7 +641,14 @@ int fw_env_write(char *name, char *value)
> /*
> * Append new definition at the end
> */
> - for (env = environment.data; *env || *(env + 1); ++env)
> + for (nxt = environment.data; !(*nxt); ++nxt) {
> + if (nxt >= &environment.data[ENV_SIZE]) {
> + fprintf (stderr, "## Error: "
> + "environment is empty\n");
> + return -1;
> + }
> + }
> + for (env = nxt; *env || *(env + 1); ++env)
> ;
> if (env > environment.data)
> ++env;
More information about the U-Boot
mailing list