From: Kamal Mostafa <kamal@canonical.com>
To: Dan Carpenter <error27@gmail.com>
Cc: linux-sparse@vger.kernel.org, smatch@vger.kernel.org
Subject: Re: [PATCH] recognize binary constants
Date: Thu, 08 Sep 2011 10:47:30 -0700 [thread overview]
Message-ID: <1315504050.2011.16.camel@marconi> (raw)
In-Reply-To: <20110908170734.GB17041@mwanda>
[-- 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 --]
next parent reply other threads:[~2011-09-09 0:47 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1315434714.1892.7.camel@marconi>
[not found] ` <20110908170734.GB17041@mwanda>
2011-09-08 17:47 ` Kamal Mostafa [this message]
2011-09-08 18:11 ` [PATCH] recognize binary constants Dan Carpenter
2011-11-15 19:35 ` Dan Carpenter
2011-11-17 1:36 ` Christopher Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1315504050.2011.16.camel@marconi \
--to=kamal@canonical.com \
--cc=error27@gmail.com \
--cc=linux-sparse@vger.kernel.org \
--cc=smatch@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).