Re: Patch removed from CVS
"Nikos Balkanas" <[email protected]>
| Newsgroups | gmane.comp.mobile.kannel.devel |
|---|---|
| Message-ID | <001d01c981ac$dfa06a80$02b2a8c0@tardis> |
You are absolutely right. Couldn't figure out the logic behind the existing type casting. I believe that now it is OK. BR, Nikos ----- Original Message ----- From: "Martin Conte Mac Donell" <[email protected]> To: "Nikos Balkanas" <[email protected]> Cc: "Alexander Malysh" <[email protected]>; <[email protected]> Sent: Thursday, January 29, 2009 2:00 AM Subject: Re: Patch removed from CVS > On Wed, Jan 28, 2009 at 8:58 PM, Nikos Balkanas <[email protected]> > wrote: >> Hi all, >> >> Attached patch to gwlib/octstr.c provides support for %ll and %llu in >> octstr_format. To do that I introduced a new format->type: 'L' for long >> long >> variables. This is a prerequisite patch for #460. >> >> Please vote, and if possible test (I have tested it only with my demo >> program, not kannel). >> >> BR, >> Nikos > > Why default cases are casted to (short) and (unsigned short) respectively? > > Also format->prec is already long, so you don't need: > > + n = (long) format->prec; > > M
patch.diff
(application/octet-stream, 2.5 KB)
Index: gwlib/octstr.c
===================================================================
RCS file: /home/cvs/gateway/gwlib/octstr.c,v
retrieving revision 1.182
diff -u -r1.182 octstr.c
--- gwlib/octstr.c 12 Jan 2009 16:46:53 -0000 1.182
+++ gwlib/octstr.c 29 Jan 2009 00:55:40 -0000
@@ -2221,10 +2221,18 @@
switch (**fmt)
{
case 'h':
- case 'l':
format->type = **fmt;
++(*fmt);
break;
+ case 'l':
+ if (*(*fmt + 1) == 'l')
+ {
+ format->type = 'L';
+ ++(*fmt);
+ }
+ else format->type = **fmt;
+ ++(*fmt);
+ break;
}
}
@@ -2234,8 +2242,8 @@
{
Octstr *new;
char *s, *pad;
- long n;
- unsigned long u;
+ long long n;
+ unsigned long long u;
char tmpfmt[1024];
char tmpbuf[1024];
char c;
@@ -2252,16 +2260,20 @@
case 'd':
case 'i':
- switch (format->type) {
- case 'l':
- n = va_arg(VALST(args), long);
- break;
- case 'h':
- n = (short) va_arg(VALST(args), int);
- break;
- default:
- n = va_arg(VALST(args), int);
- break;
+ switch (format->type)
+ {
+ case 'L':
+ n = va_arg(VALST(args), long long);
+ break;
+ case 'l':
+ n = va_arg(VALST(args), long);
+ break;
+ case 'h':
+ n = (short) va_arg(VALST(args), int);
+ break;
+ default:
+ n = va_arg(VALST(args), int);
+ break;
}
new = octstr_create("");
octstr_append_decimal(new, n);
@@ -2271,18 +2283,22 @@
case 'u':
case 'x':
case 'X':
- switch (format->type) {
- case 'l':
- u = va_arg(VALST(args), unsigned long);
- break;
- case 'h':
- u = (unsigned short) va_arg(VALST(args), unsigned int);
- break;
- default:
- u = va_arg(VALST(args), unsigned int);
- break;
- }
- tmpfmt[0] = '%';
+ switch (format->type)
+ {
+ case 'l':
+ u = va_arg(VALST(args), unsigned long);
+ break;
+ case 'L':
+ u = va_arg(VALST(args), unsigned long long);
+ break;
+ case 'h':
+ u = (unsigned short) va_arg(VALST(args), unsigned int);
+ break;
+ default:
+ u = va_arg(VALST(args), unsigned int);
+ break;
+ }
+ tmpfmt[0] = '%';
tmpfmt[1] = 'l';
tmpfmt[2] = **fmt;
tmpfmt[3] = '\0';