Author: hbelusca
Date: Sun Apr 5 16:28:10 2015
New Revision: 67062
URL:
http://svn.reactos.org/svn/reactos?rev=67062&view=rev
Log:
[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).
Modified:
trunk/reactos/base/shell/cmd/set.c
Modified: trunk/reactos/base/shell/cmd/set.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/shell/cmd/set.c?rev=6…
==============================================================================
--- trunk/reactos/base/shell/cmd/set.c [iso-8859-1] (original)
+++ trunk/reactos/base/shell/cmd/set.c [iso-8859-1] Sun Apr 5 16:28:10 2015
@@ -224,18 +224,14 @@
ident[identlen] = 0; \
p += identlen;
-static BOOL
-seta_identval(LPCTSTR ident, INT* result)
+static INT
+seta_identval(LPCTSTR ident)
{
LPCTSTR identVal = GetEnvVarOrSpecial ( ident );
if ( !identVal )
- {
- /* TODO FIXME - what to do upon failure? */
- *result = 0;
- return FALSE;
- }
- *result = _tcstol ( identVal, NULL, 0 );
- return TRUE;
+ return 0;
+ else
+ return _tcstol ( identVal, NULL, 0 );
}
static BOOL
@@ -303,8 +299,7 @@
LPTSTR ident;
INT identlen;
PARSE_IDENT(ident,identlen,p);
- if ( !seta_identval ( ident, result ) )
- return FALSE;
+ *result = seta_identval ( ident );
}
else
{
@@ -404,8 +399,15 @@
switch ( op )
{
case '<':
- lval <<= rval;
+ {
+ /* Shift left has to be a positive number, 0-31 otherwise 0 is returned,
+ * which differs from the compiler (for example gcc) so being explicit. */
+ if (rval < 0 || rval >= (8 * sizeof(lval)))
+ lval = 0;
+ else
+ lval <<= rval;
break;
+ }
case '>':
lval >>= rval;
break;
@@ -467,16 +469,23 @@
if ( !seta_assignment ( &p, &exprval ) )
return FALSE;
- if ( !seta_identval ( ident, &identval ) )
- identval = 0;
+ identval = seta_identval ( ident );
+
switch ( op )
{
case '=':
identval = exprval;
break;
case '<':
- identval <<= exprval;
+ {
+ /* Shift left has to be a positive number, 0-31 otherwise 0 is returned,
+ * which differs from the compiler (for example gcc) so being explicit. */
+ if (exprval < 0 || exprval >= (8 * sizeof(identval)))
+ identval = 0;
+ else
+ identval <<= exprval;
break;
+ }
case '>':
identval >>= exprval;
break;