* Re: [PATCH] recognize binary constants [not found] ` <20110908170734.GB17041@mwanda> @ 2011-09-08 17:47 ` Kamal Mostafa 2011-09-08 18:11 ` Dan Carpenter 2011-11-15 19:35 ` Dan Carpenter 1 sibling, 1 reply; 4+ messages in thread From: Kamal Mostafa @ 2011-09-08 17:47 UTC (permalink / raw) To: Dan Carpenter; +Cc: linux-sparse, smatch [-- Attachment #1: Type: text/plain, Size: 1674 bytes --] A small change to your patch, Dan: I added a call to tolower(), since "0B11" is also a valid syntax. -Kamal --------------------------------------------------------------------------- From a9273391fe5f410321a0668e18beaebce086e23d Mon Sep 17 00:00:00 2001 From: Kamal Mostafa <kamal@canonical.com> Date: Thu, 8 Sep 2011 10:34:27 -0700 Subject: [PATCH] recognize binary constants Sparse doesn't parse binary constants properly so the following code generates an error: x = 0b11; test.c:5:17: error: constant 0b11 is not a valid number Reported-by: Kamal Mostafa <kamal@canonical.com> Signed-off-by: Dan Carpenter <error27@gmail.com> Signed-off-by: Kamal Mostafa <kamal@canonical.com> --- expression.c | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-) diff --git a/expression.c b/expression.c index 7e06e60..07d6846 100644 --- a/expression.c +++ b/expression.c @@ -268,6 +268,13 @@ static struct token *string_expression(struct token *token, struct expression *e #define ULLONG_MAX (~0ULL) #endif +static unsigned long long parse_num(const char *nptr, char **end) +{ + if (nptr[0] == '0' && tolower(nptr[1]) == 'b') + return strtoull(&nptr[2], end, 2); + return strtoull(nptr, end, 0); +} + static void get_number_value(struct expression *expr, struct token *token) { const char *str = token->number; @@ -279,7 +286,7 @@ static void get_number_value(struct expression *expr, struct token *token) int bits; errno = 0; - value = strtoull(str, &end, 0); + value = parse_num(str, &end); if (end == str) goto Float; if (value == ULLONG_MAX && errno == ERANGE) -- 1.7.4.1 [-- Attachment #2: This is a digitally signed message part --] [-- Type: application/pgp-signature, Size: 836 bytes --] ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] recognize binary constants 2011-09-08 17:47 ` [PATCH] recognize binary constants Kamal Mostafa @ 2011-09-08 18:11 ` Dan Carpenter 0 siblings, 0 replies; 4+ messages in thread From: Dan Carpenter @ 2011-09-08 18:11 UTC (permalink / raw) To: Kamal Mostafa; +Cc: linux-sparse, smatch On Thu, Sep 08, 2011 at 10:47:30AM -0700, Kamal Mostafa wrote: > A small change to your patch, Dan: I added a call to tolower(), since > "0B11" is also a valid syntax. > Doh... Good point. Thanks. regards, dan carpenter ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] recognize binary constants [not found] ` <20110908170734.GB17041@mwanda> 2011-09-08 17:47 ` [PATCH] recognize binary constants Kamal Mostafa @ 2011-11-15 19:35 ` Dan Carpenter 2011-11-17 1:36 ` Christopher Li 1 sibling, 1 reply; 4+ messages in thread From: Dan Carpenter @ 2011-11-15 19:35 UTC (permalink / raw) To: linux-sparse; +Cc: Kamal Mostafa, smatch On 9/8/11, Dan Carpenter <error27@gmail.com> wrote: > Sparse doesn't parse binary constants properly so the following code > generates an error: > > x = 0b11; > > test.c:5:17: error: constant 0b11 is not a valid number > > Reported-by: Kamal Mostafa <kamal@canonical.com> > Signed-off-by: Dan Carpenter <error27@gmail.com> I sent this patch before but the git tree was offline so everything was dead. regards, dan carpenter ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] recognize binary constants 2011-11-15 19:35 ` Dan Carpenter @ 2011-11-17 1:36 ` Christopher Li 0 siblings, 0 replies; 4+ messages in thread From: Christopher Li @ 2011-11-17 1:36 UTC (permalink / raw) To: Dan Carpenter; +Cc: linux-sparse, Kamal Mostafa, smatch On Tue, Nov 15, 2011 at 11:35 AM, Dan Carpenter <error27@gmail.com> wrote: > On 9/8/11, Dan Carpenter <error27@gmail.com> wrote: >> Sparse doesn't parse binary constants properly so the following code >> generates an error: >> >> x = 0b11; >> >> test.c:5:17: error: constant 0b11 is not a valid number >> >> Reported-by: Kamal Mostafa <kamal@canonical.com> >> Signed-off-by: Dan Carpenter <error27@gmail.com> > > I sent this patch before but the git tree was offline so everything > was dead. Thanks for the reminder. The patch looks fine. I will apply it. Chris -- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2011-11-17 1:36 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- [not found] <1315434714.1892.7.camel@marconi> [not found] ` <20110908170734.GB17041@mwanda> 2011-09-08 17:47 ` [PATCH] recognize binary constants Kamal Mostafa 2011-09-08 18:11 ` Dan Carpenter 2011-11-15 19:35 ` Dan Carpenter 2011-11-17 1:36 ` Christopher Li
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).