On 2011-01-15 07.05, Philip Guenther wrote:
> If you're going to email diffs, you MUST turn off 'format=flowed', as
> Thunderbird munged the whitespace on your diffs enough to make them
> break with "patch -l". Thunderbird has an option for that; find it
> and use it.
Check.
for (i=0; i<100; i++)
fputs("Will do homework better.\t", blackboard);
> ...
>> -is_integer(struct val *vp, int *r)
>> +is_integer(struct val *vp, int64_t *r)
>> {
>> char *s;
>> - int neg;
>> - int i;
>> + int64_t neg;
>> + int64_t i;
>
> You make 'neg' int64_t why?
Because I'm obviously sloppy. :-) I read the code badly, thinking neg
would be set to -1 if negative, and then the result multiplied by it. In
reality of course, it is just a flag and the result, if negative, is
multiplied by the constant -1. I'll revert it to an int.
> ...
>> @@ -509,7 +509,7 @@
>> }
>>
>> if (vp->type == integer)
>> - printf("%d\n", vp->u.i);
>> + printf("%ld\n", vp->u.i);
>
> My crystal ball says you use amd64 platform and not i386, as the above
> works on LP64 and fails on ILP32LL64. The format string should be
> "%lld\n".
You are right of course. I missed to update that when I changed the diff
from long to int64_t at Teds recommendation, and I also failed to test
it afterwards on an i386 platform (which are the only two I have access
to at the moment).
> Related: try this with your version:
>
> expr 42949673000 : '.*'
>
> Your diff will have that return 2, when the correct answer is 11: the
> format string in the asprintf() call in to_string() needs to be
> updated:
>
> - if (asprintf(&tmp, "%d", vp->u.i) == -1)
> + if (asprintf(&tmp, "%lld", vp->u.i) == -1)
Check. Missed that one too. I knew there was a downside to reading code
when you're really too tired...
Thanks for the input.
/Benny
----8<--------8<--------8<--------8<--------8<---- (cut)
Index: expr.c
===================================================================
RCS file: /cvs/src/bin/expr/expr.c,v
retrieving revision 1.17
diff -u -r1.17 expr.c
--- expr.c 21 Jun 2006 18:28:24 -0000 1.17
+++ expr.c 15 Jan 2011 12:26:57 -0000
@@ -14,11 +14,11 @@
#include <regex.h>
#include <err.h>
-struct val *make_int(int);
+struct val *make_int(int64_t);
struct val *make_str(char *);
void free_value(struct val *);
-int is_integer(struct val *, int *);
-int to_integer(struct val *);
+int is_integer(struct val *, int64_t *);
+int64_t to_integer(struct val *);
void to_string(struct val *);
int is_zero_or_null(struct val *);
void nexttoken(int);
@@ -44,7 +44,7 @@
union {
char *s;
- int i;
+ int64_t i;
} u;
};
@@ -53,7 +53,7 @@
char **av;
struct val *
-make_int(int i)
+make_int(int64_t i)
{
struct val *vp;
@@ -92,11 +92,11 @@
/* determine if vp is an integer; if so, return it's value in *r */
int
-is_integer(struct val *vp, int *r)
+is_integer(struct val *vp, int64_t *r)
{
char *s;
int neg;
- int i;
+ int64_t i;
if (vp->type == integer) {
*r = vp->u.i;
@@ -133,10 +133,10 @@
/* coerce to vp to an integer */
-int
+int64_t
to_integer(struct val *vp)
{
- int r;
+ int64_t r;
if (vp->type == integer)
return 1;
@@ -161,7 +161,7 @@
if (vp->type == string)
return;
- if (asprintf(&tmp, "%d", vp->u.i) == -1)
+ if (asprintf(&tmp, "%lld", vp->u.i) == -1)
err(3, NULL);
vp->type = string;
@@ -375,7 +375,7 @@
{
struct val *l, *r;
enum token op;
- int v = 0, li, ri;
+ int64_t v = 0, li, ri;
l = eval3();
while ((op = token) == EQ || op == NE || op == LT || op == GT ||
@@ -509,7 +509,7 @@
}
if (vp->type == integer)
- printf("%d\n", vp->u.i);
+ printf("%lld\n", vp->u.i);
else
printf("%s\n", vp->u.s);
----8<--------8<--------8<--------8<--------8<---- (cut)
--
internetlabbet.se / work: +46 8 551 124 80 / "Words must
Benny Lvfgren / mobile: +46 70 718 11 90 / be weighed,
/ fax: +46 8 551 124 89 / not counted."
/ email: benny -at- internetlabbet.se