* Re: [ECOS] Bug in server_test.c
[not found] <fs8du7$djn$2@ger.gmane.org>
@ 2008-04-13 18:39 ` Andrew Lunn
0 siblings, 0 replies; only message in thread
From: Andrew Lunn @ 2008-04-13 18:39 UTC (permalink / raw)
To: Grant Edwards; +Cc: eCos Patches
[-- Attachment #1: Type: text/plain, Size: 910 bytes --]
On Mon, Mar 24, 2008 at 02:30:32PM +0000, Grant Edwards wrote:
> There appears to be a bug in server_test.c:
>
> ecos-opt/net/net/common/current/tests/server_test.c
>
> 94
> 95 #ifdef CYGPKG_LIBC_STDIO
> 96 sprintf(buf, "Hello %s:%d\n", inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));
> 97 #else
> 98 strcpy(buf, "Hello ");
> 99 strcat(buf, inet_ntoa(client_addr.sin_addr));
> 100 strcat(buf,":");
> 101 strcat(buf, atoi(ntohs(client_addr.sin_port)));
> 102 strcat(buf,"\n");
> 103 #endif
>
> In line 101, the call to atoi() doesn't look right. Shouldn't
> that be a call to itoa() (assuming such a function existed)?
No, it does not exist. I replaced the whole code fragment with
diag_sprintf() which always exists since it is in infra.
Thanks for pointing out the error,
Andrew
[-- Attachment #2: atoi_typo.diff --]
[-- Type: text/x-diff, Size: 1895 bytes --]
Index: packages/net/common/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos-opt/net/net/common/current/ChangeLog,v
retrieving revision 1.82
diff -u -r1.82 ChangeLog
--- packages/net/common/current/ChangeLog 6 Jan 2008 11:13:51 -0000 1.82
+++ packages/net/common/current/ChangeLog 13 Apr 2008 18:38:05 -0000
@@ -1,3 +1,9 @@
+2008-04-13 Andrew Lunn <andrew.lunn@ascom.ch>
+
+ * tests/server_test.c (server_test): Fix typo with atoi which
+ should really be ultoa(). Cleanup to use diag_sprintf() which is
+ always available. Bug reported by Grant Edwards.
+
2007-12-21 Oyvind Harboe <oyvind.harboe@zylin.com>
* src/tftp_client.c, include/arpa/tftp.h, cdl/net.cdl: tftp
Index: packages/net/common/current/tests/server_test.c
===================================================================
RCS file: /cvs/ecos/ecos-opt/net/net/common/current/tests/server_test.c,v
retrieving revision 1.2
diff -u -r1.2 server_test.c
--- packages/net/common/current/tests/server_test.c 16 Sep 2005 15:15:14 -0000 1.2
+++ packages/net/common/current/tests/server_test.c 13 Apr 2008 18:38:05 -0000
@@ -92,15 +92,7 @@
getpeername(client, (struct sockaddr *)&client_addr, &client_len);
diag_printf("connection from %s:%d\n", inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));
-#ifdef CYGPKG_LIBC_STDIO
- sprintf(buf, "Hello %s:%d\n", inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));
-#else
- strcpy(buf, "Hello ");
- strcat(buf, inet_ntoa(client_addr.sin_addr));
- strcat(buf,":");
- strcat(buf, atoi(ntohs(client_addr.sin_port)));
- strcat(buf,"\n");
-#endif
+ diag_sprintf(buf, "Hello %s:%d\n", inet_ntoa(client_addr.sin_addr), ntohs(client_addr.sin_port));
write(client, buf, strlen(buf));
tv.tv_sec = 5;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2008-04-13 18:39 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <fs8du7$djn$2@ger.gmane.org>
2008-04-13 18:39 ` [ECOS] Bug in server_test.c Andrew Lunn
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 read-only IMAP folder(s) and NNTP newsgroup(s).