From 5cf2e760b602686c9a757e3978179f47b451c111 Mon Sep 17 00:00:00 2001 From: jimblandy Date: Wed, 24 Feb 2010 19:17:54 +0000 Subject: Breakpad processor: Support negative literals in the postfix evaluator. Some versions of the libstdc++, the GNU standard C++ library, have stream extractors for unsigned integer values that permit a leading '-' sign (6.0.13); others do not (6.0.9). Regardless of the behavior of the extractors, Breakpad postfix expressions should support negative literals. a=jimblandy, r=nealsid git-svn-id: http://google-breakpad.googlecode.com/svn/trunk@537 4c0a9323-5329-0410-9bdc-e9ce6186880e --- src/processor/postfix_evaluator-inl.h | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'src/processor') diff --git a/src/processor/postfix_evaluator-inl.h b/src/processor/postfix_evaluator-inl.h index 9c1fc84e..b1252f68 100644 --- a/src/processor/postfix_evaluator-inl.h +++ b/src/processor/postfix_evaluator-inl.h @@ -246,16 +246,30 @@ PostfixEvaluator::PopValueOrIdentifier( string token = stack_.back(); stack_.pop_back(); - // First, try to treat the value as a literal. In order for this to - // succed, the entire string must be parseable as ValueType. If this - // isn't possible, it can't be a literal, so treat it as an identifier - // instead. + // First, try to treat the value as a literal. Literals may have leading + // '-' sign, and the entire remaining string must be parseable as + // ValueType. If this isn't possible, it can't be a literal, so treat it + // as an identifier instead. + // + // Some versions of the libstdc++, the GNU standard C++ library, have + // stream extractors for unsigned integer values that permit a leading + // '-' sign (6.0.13); others do not (6.0.9). Since we require it, we + // handle it explicitly here. istringstream token_stream(token); ValueType literal; + bool negative; + if (token_stream.peek() == '-') { + negative = true; + token_stream.get(); + } else { + negative = false; + } if (token_stream >> literal && token_stream.peek() == EOF) { if (value) { *value = literal; } + if (negative) + *value = -*value; return POP_RESULT_VALUE; } else { if (identifier) { -- cgit v1.2.1