This is the mail archive of the ecos-patches@sourceware.org mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [ECOS] Bug in server_test.c


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
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;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]