* sprintf with mips
@ 2008-02-06 19:16 Christian Stalp
2008-02-06 19:45 ` Manning, Gary L
2008-02-06 21:21 ` Eric Polino
0 siblings, 2 replies; 10+ messages in thread
From: Christian Stalp @ 2008-02-06 19:16 UTC (permalink / raw)
To: linux-c-programming
Hello out there,
are there any known problems with sprintf under mips? I spend some time to make this code runnable:
sprintf(insertvalues, " %d , ' %s ' , %d ", counter, "192.168.1.1", mytraffic->num_frames);
printf("input-string: %s\n", insertvalues);
This works properly under x86 but if I run this under mips, the string is empty! Even if the variable 'counter' is uninitialized or 'mytraffic->num_frames' (which is not the case, I can see the values if I dump them directly with printf) there should be at least that IP-address-string which should be inserted! This is weired. Has anybody an idea what the problem is here?
Thank you.
Gruss Christian
--
GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS.
Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/freemail
^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: sprintf with mips
2008-02-06 19:16 Christian Stalp
@ 2008-02-06 19:45 ` Manning, Gary L
2008-02-06 21:21 ` Eric Polino
1 sibling, 0 replies; 10+ messages in thread
From: Manning, Gary L @ 2008-02-06 19:45 UTC (permalink / raw)
To: Christian Stalp, linux-c-programming
How is insertvalues defined?
Gary
-----Original Message-----
From: linux-c-programming-owner@vger.kernel.org
[mailto:linux-c-programming-owner@vger.kernel.org] On Behalf Of
Christian Stalp
Sent: Wednesday, February 06, 2008 11:16 AM
To: linux-c-programming@vger.kernel.org
Subject: sprintf with mips
Hello out there,
are there any known problems with sprintf under mips? I spend some time
to make this code runnable:
sprintf(insertvalues, " %d , ' %s ' , %d ", counter, "192.168.1.1",
mytraffic->num_frames);
printf("input-string: %s\n", insertvalues);
This works properly under x86 but if I run this under mips, the string
is empty! Even if the variable 'counter' is uninitialized or
'mytraffic->num_frames' (which is not the case, I can see the values if
I dump them directly with printf) there should be at least that
IP-address-string which should be inserted! This is weired. Has anybody
an idea what the problem is here?
Thank you.
Gruss Christian
^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: sprintf with mips
@ 2008-02-06 19:58 Christian Stalp
0 siblings, 0 replies; 10+ messages in thread
From: Christian Stalp @ 2008-02-06 19:58 UTC (permalink / raw)
To: linux-c-programming
>How is insertvalues defined?
char insertvalues[256];
memset (insertvalues, 0x0, 256 );
Gruss Christian
--
Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" 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] 10+ messages in thread
* RE: sprintf with mips
@ 2008-02-06 20:14 Christian Stalp
0 siblings, 0 replies; 10+ messages in thread
From: Christian Stalp @ 2008-02-06 20:14 UTC (permalink / raw)
To: linux-c-programming
I use "snprintf" now. And with that it works.
I don't know if we should investigate this further? If you have any questions I can test anyway.
Gruss Christian
--
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" 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] 10+ messages in thread
* Re: sprintf with mips
2008-02-06 19:16 Christian Stalp
2008-02-06 19:45 ` Manning, Gary L
@ 2008-02-06 21:21 ` Eric Polino
1 sibling, 0 replies; 10+ messages in thread
From: Eric Polino @ 2008-02-06 21:21 UTC (permalink / raw)
Cc: linux-c-programming
On Feb 6, 2008 2:16 PM, Christian Stalp <christian.stalp@gmx.de> wrote:
> Hello out there,
> are there any known problems with sprintf under mips? I spend some time to make this code runnable:
>
> sprintf(insertvalues, " %d , ' %s ' , %d ", counter, "192.168.1.1", mytraffic->num_frames);
> printf("input-string: %s\n", insertvalues);
>
I don't know if this really matters...but why are you doing this this
way? Why not just do it in one line with
printf("input-string: %d , ' %s ' , %d \n", counter, "192.168.1.1",
mytraffic->num_frames);
Cheers,
Eric
> This works properly under x86 but if I run this under mips, the string is empty! Even if the variable 'counter' is uninitialized or 'mytraffic->num_frames' (which is not the case, I can see the values if I dump them directly with printf) there should be at least that IP-address-string which should be inserted! This is weired. Has anybody an idea what the problem is here?
>
> Thank you.
>
> Gruss Christian
>
>
> --
> GMX FreeMail: 1 GB Postfach, 5 E-Mail-Adressen, 10 Free SMS.
> Alle Infos und kostenlose Anmeldung: http://www.gmx.net/de/go/freemail
> -
> To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
--
"None are more hopelessly enslaved than those who falsely believe they
are free."
--Goethe
"Freedom is living without government coercion."
--Ron Paul (www.ronpaul2008.com)
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: sprintf with mips
@ 2008-02-06 22:48 Christian Stalp
2008-02-07 0:10 ` Paul Jackson
0 siblings, 1 reply; 10+ messages in thread
From: Christian Stalp @ 2008-02-06 22:48 UTC (permalink / raw)
To: linux-c-programming; +Cc: Eric Polino
the second printf is only for debugging purpose. The whole string 'insertvalues' is used for SQL-query later.
Eric Polino wrote:
>
>
> On Feb 6, 2008 2:16 PM, Christian Stalp <christian.stalp@gmx.de> wrote:
>
> Hello out there,
> are there any known problems with sprintf under mips? I spend some time to make this code runnable:
>
> sprintf(insertvalues, " %d , ' %s ' , %d ", counter, "192.168.1.1", mytraffic->num_frames);
> printf("input-string: %s\n", insertvalues);
>
>
> I don't know if this really matters...but why are you doing this this way? Why not just do it in one line with
>
> printf("input-string: %d , ' %s ' , %d \n", counter, "192.168.1.1", mytraffic->num_frames);
--
Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten
Browser-Versionen downloaden: http://www.gmx.net/de/go/browser
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: sprintf with mips
2008-02-06 22:48 Christian Stalp
@ 2008-02-07 0:10 ` Paul Jackson
0 siblings, 0 replies; 10+ messages in thread
From: Paul Jackson @ 2008-02-07 0:10 UTC (permalink / raw)
To: Christian Stalp; +Cc: linux-c-programming, aluink
> are there any known problems with sprintf under mips?
Is there any chance that some other line of code, perhaps
writing an adjacent variable, is overflowing onto the
front of this insertvalues[] array, between the sprintf
and the printf?
In other words, I'll wager that whatever bug you're seeing
is neither in the code fragements quoted here, nor in the
sprintf libc code, but in some other nearby code.
--
I won't rest till it's the best ...
Programmer, Linux Scalability
Paul Jackson <pj@sgi.com> 1.940.382.4214
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: sprintf with mips
@ 2008-02-10 22:25 Christian Stalp
2008-02-12 14:17 ` Stephen Kratzer
2008-02-12 16:31 ` Paul Jackson
0 siblings, 2 replies; 10+ messages in thread
From: Christian Stalp @ 2008-02-10 22:25 UTC (permalink / raw)
To: linux-c-programming
The whole procedure is here: (its a thread!)
void *dblogger_fn (void *arg)
{
char insertvalues[256];
memset (insertvalues, 0x0, 256 );
conn = PQconnectdb("host=192.168.1.2 dbname=wlan_db user=gavle password=brynaes");
tabellename = "traffic";
if (PQstatus(conn) == CONNECTION_BAD)
{
fprintf(stderr, "Connection to database '%s' failed.\n",dbName);
fprintf(stderr, "%s", PQerrorMessage(conn));
exit_nicely(conn);
}
else if (PQstatus(conn) == CONNECTION_OK)
{
printf("Connected with database ...\n");
printf("Datenbank : %s\n", PQdb(conn));
printf("User : %s\n", PQuser(conn));
}
while(1)
{
sleep(500);
snprintf(insertvalues, 255 ," %d , ' %s ' , %d ", counter, "192.168.1.1", mytraffic->num_frames);
printf("input-string: %s\n", insertvalues);
printf("Counter: %d\n", counter);
insertinto(dbName, conn, tabellename, insertvalues);
counter++;
}
I don't know where is here a chance for an overflow? Consider, now with 'snprintf' it works, but before with sprintf there was this problem, BUT only on the mips-target board. On x86 it worked also with sprintf!
Gruss Christian
Paul Jackson wrote:
>> are there any known problems with sprintf under mips?
>
> Is there any chance that some other line of code, perhaps
> writing an adjacent variable, is overflowing onto the
> front of this insertvalues[] array, between the sprintf
> and the printf?
>
> In other words, I'll wager that whatever bug you're seeing
> is neither in the code fragements quoted here, nor in the
> sprintf libc code, but in some other nearby code.
>
--
Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger
-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" 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] 10+ messages in thread
* Re: sprintf with mips
2008-02-10 22:25 Christian Stalp
@ 2008-02-12 14:17 ` Stephen Kratzer
2008-02-12 16:31 ` Paul Jackson
1 sibling, 0 replies; 10+ messages in thread
From: Stephen Kratzer @ 2008-02-12 14:17 UTC (permalink / raw)
To: Christian Stalp; +Cc: linux-c-programming
On Sunday 10 February 2008 17:25:59 Christian Stalp wrote:
> The whole procedure is here: (its a thread!)
>
> void *dblogger_fn (void *arg)
> {
> char insertvalues[256];
> memset (insertvalues, 0x0, 256 );
> conn = PQconnectdb("host=192.168.1.2 dbname=wlan_db user=gavle
> password=brynaes"); tabellename = "traffic";
>
> if (PQstatus(conn) == CONNECTION_BAD)
> {
> fprintf(stderr, "Connection to database '%s' failed.\n",dbName);
> fprintf(stderr, "%s", PQerrorMessage(conn));
> exit_nicely(conn);
> }
> else if (PQstatus(conn) == CONNECTION_OK)
> {
> printf("Connected with database ...\n");
> printf("Datenbank : %s\n", PQdb(conn));
> printf("User : %s\n", PQuser(conn));
> }
> while(1)
> {
> sleep(500);
> snprintf(insertvalues, 255 ," %d , ' %s ' , %d ", counter,
> "192.168.1.1", mytraffic->num_frames); printf("input-string: %s\n",
> insertvalues);
> printf("Counter: %d\n", counter);
> insertinto(dbName, conn, tabellename, insertvalues);
> counter++;
> }
>
> I don't know where is here a chance for an overflow? Consider, now with
> 'snprintf' it works, but before with sprintf there was this problem, BUT
> only on the mips-target board. On x86 it worked also with sprintf!
>
> Gruss Christian
I would recommend stepping through with a debugger. It might also be worth
while to compile with the -S option (if using gcc) and peruse the MIPS
assembly.
Stephen Kratzer
Network Engineer
CTI Networks, Inc.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: sprintf with mips
2008-02-10 22:25 Christian Stalp
2008-02-12 14:17 ` Stephen Kratzer
@ 2008-02-12 16:31 ` Paul Jackson
1 sibling, 0 replies; 10+ messages in thread
From: Paul Jackson @ 2008-02-12 16:31 UTC (permalink / raw)
To: Christian Stalp; +Cc: linux-c-programming
Does the problem go away if you replace:
char insertvalues[256];
with something like:
char xx[512];
char *insertvalues = xx+128;
If that makes the problem go away, try adding additional checking
code, that puts a distinct guard pattern on both sides of the
256 payload bytes, and checks that pattern for corruption on each
iteration of the while loop.
If the "works on x86 but not mips" is not helping you solve this,
then -ignore- that detail. This is similar to the "worked before,
but not now, and I only changed such-and-such". Sometimes such clues
are reality giving you a head fake. Instead, just debug the mips case,
as if it were all you knew. In this particular case, you could explain
the x86 vs mips difference with the hypothesis that since the memory
and stack layout are different, perhaps there is a long standing bug
on both architectures that only happens to manifest itself on the
mips architecture. But you don't need any such explaination -- always
try ignoring such 'strange coincidences' if they are blocking you.
Does this fail sometimes on the -very- first iteration of the
"while(1)" loop, or always sometimes later.
Could some other thread be trampling insertvalues[]?
Could the following line trample insertvalues[]:
insertinto(dbName, conn, tabellename, insertvalues);
--
I won't rest till it's the best ...
Programmer, Linux Scalability
Paul Jackson <pj@sgi.com> 1.940.382.4214
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2008-02-12 16:31 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-06 20:14 sprintf with mips Christian Stalp
-- strict thread matches above, loose matches on Subject: below --
2008-02-10 22:25 Christian Stalp
2008-02-12 14:17 ` Stephen Kratzer
2008-02-12 16:31 ` Paul Jackson
2008-02-06 22:48 Christian Stalp
2008-02-07 0:10 ` Paul Jackson
2008-02-06 19:58 Christian Stalp
2008-02-06 19:16 Christian Stalp
2008-02-06 19:45 ` Manning, Gary L
2008-02-06 21:21 ` Eric Polino
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).