linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* 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-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 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: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
* 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

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-10 22:25 sprintf with mips Christian Stalp
2008-02-12 14:17 ` Stephen Kratzer
2008-02-12 16:31 ` Paul Jackson
  -- strict thread matches above, loose matches on Subject: below --
2008-02-06 22:48 Christian Stalp
2008-02-07  0:10 ` Paul Jackson
2008-02-06 20:14 Christian Stalp
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).