From cdd8fe239af661f1d36be370ddff08969e77ce11 Mon Sep 17 00:00:00 2001 From: patacongo Date: Sat, 30 Jun 2007 22:39:20 +0000 Subject: [PATCH] Add environment variable test; fix several detected bugs git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@298 42af7a65-404d-4744-a932-0658087f49c3 --- ChangeLog | 4 +++- Documentation/NuttX.html | 4 +++- sched/env_dup.c | 4 ++-- sched/env_getenv.c | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index adf20a906d..81188709c1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -191,6 +191,8 @@ * Add environment variables APIs: environ, getenv, putenv, clearenv, setenv, unsetenv * Correct an error in realloc() when the block is extended "down" in memory. - In this case, the old memory contents need to be copied to the new location. + In this case, the old memory contents need to be copied to the new location + and an allocated bit was not being set. + * examples/ostest: Added an environment variable test. * Started m68322 diff --git a/Documentation/NuttX.html b/Documentation/NuttX.html index e19cf3d0d3..fad801a840 100644 --- a/Documentation/NuttX.html +++ b/Documentation/NuttX.html @@ -628,7 +628,9 @@ Other memory: * Add environment variables APIs: environ, getenv, putenv, clearenv, setenv, unsetenv * Correct an error in realloc() when the block is extended "down" in memory. - In this case, the old memory contents need to be copied to the new location. + In this case, the old memory contents need to be copied to the new location + and an allocated bit was not being set. + * examples/ostest: Added an environment variable test. * Started m68322 diff --git a/sched/env_dup.c b/sched/env_dup.c index 0ee1cbc81d..671b8ea7b7 100644 --- a/sched/env_dup.c +++ b/sched/env_dup.c @@ -99,7 +99,7 @@ int env_dup(FAR _TCB *ptcb) { /* Yes..The parent task has an environment, duplicate it */ - size_t envlen = ptcb->envp->ev_alloc; + size_t envlen = parent->envp->ev_alloc; envp = (environ_t*)malloc(SIZEOF_ENVIRON_T( envlen )); if (!envp) { @@ -109,7 +109,7 @@ int env_dup(FAR _TCB *ptcb) { envp->ev_crefs = 1; envp->ev_alloc = envlen; - memcmp( envp->ev_env, ptcb->envp->ev_env, envlen ); + memcpy( envp->ev_env, parent->envp->ev_env, envlen ); } } diff --git a/sched/env_getenv.c b/sched/env_getenv.c index a1de739a97..91e9748452 100644 --- a/sched/env_getenv.c +++ b/sched/env_getenv.c @@ -100,7 +100,7 @@ FAR char *getenv(const char *name) /* Check if the variable exists */ - if ( envp && (pvar = env_findvar(envp, name)) != NULL) + if ( !envp || (pvar = env_findvar(envp, name)) == NULL) { ret = ENOENT; goto errout_with_lock;