Skip to content

Commit 2480c56

Browse files
committed
[CMD]: Some fixes for SET /A command:
- If we do arithmetics using an non-defined env-var, the latter is automatically understood to be zero. - If one left-shifts more than 31 bits (or left-shifts a negative number of bits), the result is automaticaly set to zero (checked on Windows'cmd + with cmd_winetest + wine cmd code). svn path=/trunk/; revision=67062
1 parent 11cc096 commit 2480c56

File tree

1 file changed

+24
-15
lines changed
  • reactos/base/shell/cmd

1 file changed

+24
-15
lines changed

reactos/base/shell/cmd/set.c

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -224,18 +224,14 @@ ident_len(LPCTSTR p)
224224
ident[identlen] = 0; \
225225
p += identlen;
226226

227-
static BOOL
228-
seta_identval(LPCTSTR ident, INT* result)
227+
static INT
228+
seta_identval(LPCTSTR ident)
229229
{
230230
LPCTSTR identVal = GetEnvVarOrSpecial ( ident );
231231
if ( !identVal )
232-
{
233-
/* TODO FIXME - what to do upon failure? */
234-
*result = 0;
235-
return FALSE;
236-
}
237-
*result = _tcstol ( identVal, NULL, 0 );
238-
return TRUE;
232+
return 0;
233+
else
234+
return _tcstol ( identVal, NULL, 0 );
239235
}
240236

241237
static BOOL
@@ -303,8 +299,7 @@ seta_unaryTerm(LPCTSTR* p_, INT* result)
303299
LPTSTR ident;
304300
INT identlen;
305301
PARSE_IDENT(ident,identlen,p);
306-
if ( !seta_identval ( ident, result ) )
307-
return FALSE;
302+
*result = seta_identval ( ident );
308303
}
309304
else
310305
{
@@ -404,8 +399,15 @@ seta_bitAndTerm(LPCTSTR* p_, INT* result)
404399
switch ( op )
405400
{
406401
case '<':
407-
lval <<= rval;
402+
{
403+
/* Shift left has to be a positive number, 0-31 otherwise 0 is returned,
404+
* which differs from the compiler (for example gcc) so being explicit. */
405+
if (rval < 0 || rval >= (8 * sizeof(lval)))
406+
lval = 0;
407+
else
408+
lval <<= rval;
408409
break;
410+
}
409411
case '>':
410412
lval >>= rval;
411413
break;
@@ -467,16 +469,23 @@ seta_assignment(LPCTSTR* p_, INT* result)
467469
if ( !seta_assignment ( &p, &exprval ) )
468470
return FALSE;
469471

470-
if ( !seta_identval ( ident, &identval ) )
471-
identval = 0;
472+
identval = seta_identval ( ident );
473+
472474
switch ( op )
473475
{
474476
case '=':
475477
identval = exprval;
476478
break;
477479
case '<':
478-
identval <<= exprval;
480+
{
481+
/* Shift left has to be a positive number, 0-31 otherwise 0 is returned,
482+
* which differs from the compiler (for example gcc) so being explicit. */
483+
if (exprval < 0 || exprval >= (8 * sizeof(identval)))
484+
identval = 0;
485+
else
486+
identval <<= exprval;
479487
break;
488+
}
480489
case '>':
481490
identval >>= exprval;
482491
break;

0 commit comments

Comments
 (0)