check allocated memory when setting SHLVL

This commit is contained in:
Grissiom 2010-10-08 09:38:06 +08:00
parent f47caefdb9
commit b9b6e867df

4
env.c
View File

@ -655,8 +655,12 @@ void env_init()
wchar_t *nshlvl, **end_nshlvl;
/* add an extra space for digit dump (9+1=10) */
size_t i = wcslen( shlvl ) + 2 * sizeof(wchar_t);
nshlvl = malloc(i);
end_nshlvl = calloc( 1, sizeof(nshlvl) );
if ( !nshlvl || !end_nshlvl )
DIE_MEM();
if ( nshlvl && swprintf( nshlvl, i,
L"%ld", wcstoul( shlvl, end_nshlvl, 10 )+1 ) != -1 )
{