stoneCC / serf

Automatically exported from code.google.com/p/serf
Apache License 2.0
0 stars 0 forks source link

compilation of test/test_context.c breaks with C89 compilers #99

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. compile test with either MSVC or with gcc -Wdeclaration-after-statement

What is the expected output? What do you see instead?
test/test_context.c: In function 'create_large_response_message':
test/test_context.c:1081:9: warning: ISO C90 forbids mixed declarations and 
code [-Wdeclaration-after-statement]
test/test_context.c: In function 'create_large_request_message':
test/test_context.c:1149:9: warning: ISO C90 forbids mixed declarations and 
code [-Wdeclaration-after-statement]
test/test_context.c: In function 'test_serf_ssl_large_response':
test/test_context.c:1761:5: warning: ISO C90 forbids mixed declarations and 
code [-Wdeclaration-after-statement]

What version of the product are you using? On what operating system?
SVN-HEAD; target Windows and NetWare.

Please provide any additional information below.
Fix:
Index: test/test_context.c
===================================================================
--- test/test_context.c (revision 1877)
+++ test/test_context.c (working copy)
@@ -1073,12 +1073,13 @@
     for (i = 1; i < num_vecs; i++)
     {
         int chunk_len = 10 * i * 3;
+        char *chunk, *buf;

         /* end with empty chunk */
         if (i == num_vecs - 1)
             chunk_len = 0;

-        char *chunk, *buf = apr_pcalloc(pool, chunk_len + 1);
+        buf = apr_pcalloc(pool, chunk_len + 1);
         for (j = 0; j < chunk_len; j += 10)
             memcpy(buf + j, "0123456789", 10);

@@ -1141,12 +1142,13 @@
     for (i = 1; i < num_vecs; i++)
     {
         int chunk_len = 10 * i * 3;
+        char *chunk, *buf;

         /* end with empty chunk */
         if (i == num_vecs - 1)
             chunk_len = 0;

-        char *chunk, *buf = apr_pcalloc(pool, chunk_len + 1);
+        buf = apr_pcalloc(pool, chunk_len + 1);
         for (j = 0; j < chunk_len; j += 10)
             memcpy(buf + j, "0123456789", 10);

@@ -1745,6 +1747,7 @@

     /* Set up a test context with a server */
     apr_pool_t *test_pool = tc->testBaton;
+    const char *response;

     status = test_https_server_setup(&tb,
                                      message_list, num_requests,
@@ -1758,7 +1761,7 @@
     CuAssertIntEquals(tc, APR_SUCCESS, status);

     /* create large chunked response message */
-    const char *response = create_large_response_message(test_pool);
+    response = create_large_response_message(test_pool);
     action_list[0].kind = SERVER_RESPOND;
     action_list[0].text = response;

you might want to add -Wdeclaration-after-statement to CFLAGS to issue a 
warning and avoid such probs in the future:
Index: SConstruct
===================================================================
--- SConstruct  (revision 1877)
+++ SConstruct  (working copy)
@@ -131,7 +131,7 @@
   ### -Wall is not available on Solaris
   ccflags = ['-std=c89', ]
   if sys.platform != 'sunos5':
-    ccflags.append(['-Wall', '-Wmissing-prototypes'])
+    ccflags.append(['-Wall', '-Wmissing-prototypes', 
'-Wdeclaration-after-statement'])
   if debug:
     ccflags.append(['-g'])
   else:

Original issue reported on code.google.com by 0x1...@googlemail.com on 31 May 2013 at 11:34

Attachments:

GoogleCodeExporter commented 9 years ago
Fixed in r1879.

Original comment by chemodax@gmail.com on 31 May 2013 at 1:10