Browse Source

ZOOKEEPER-1679. c client: use -Wdeclaration-after-statement (michi via fpj)


git-svn-id: https://svn.apache.org/repos/asf/zookeeper/trunk@1516126 13f79535-47bb-0310-9956-ffa450edef68
Flavio Paiva Junqueira 12 năm trước cách đây
mục cha
commit
c2673e4d0a
4 tập tin đã thay đổi với 15 bổ sung7 xóa
  1. 2 0
      CHANGES.txt
  2. 1 1
      src/c/Makefile.am
  3. 9 5
      src/c/src/cli.c
  4. 3 1
      src/c/src/zookeeper.c

+ 2 - 0
CHANGES.txt

@@ -547,6 +547,8 @@ IMPROVEMENTS:
 
   ZOOKEEPER-1400. Allow logging via callback instead of raw FILE pointer (michi via fpj)
 
+  ZOOKEEPER-1679. c client: use -Wdeclaration-after-statement (michi via fpj)
+
 Release 3.4.0 - 
 
 Non-backward compatible changes:

+ 1 - 1
src/c/Makefile.am

@@ -2,7 +2,7 @@
 include $(top_srcdir)/aminclude.am
 
 AM_CPPFLAGS = -I${srcdir}/include -I${srcdir}/tests -I${srcdir}/generated
-AM_CFLAGS = -Wall -Werror 
+AM_CFLAGS = -Wall -Werror -Wdeclaration-after-statement
 AM_CXXFLAGS = -Wall $(USEIPV6)
 
 LIB_LDFLAGS = -no-undefined -version-info 2

+ 9 - 5
src/c/src/cli.c

@@ -362,9 +362,8 @@ void processline(char *line) {
             fprintf(stderr, "Error %d for %s\n", rc, line);
         }
    } else if (startsWith(line, "reconfig ")) {
-           line += 9;
            int syntaxError = 0;
-
+           char* p = NULL;
            char* joining = NULL;
            char* leaving = NULL;
            char* members = NULL;
@@ -373,8 +372,8 @@ void processline(char *line) {
            int mode = 0; // 0 = not set, 1 = incremental, 2 = non-incremental
            int64_t version = -1;
 
-           char *p = strtok (strdup(line)," ");
-
+           line += 9;
+           p = strtok (strdup(line)," ");
            while (p != NULL) {
                if (strcmp(p, "-add")==0) {
                    p = strtok (NULL," ");
@@ -401,13 +400,14 @@ void processline(char *line) {
                    mode = 2;
                    members = strdup(p);
                } else if (strcmp(p, "-file")==0){
+                   FILE *fp = NULL;
                    p = strtok (NULL," ");
                    if (mode == 1 || p == NULL) {
                        syntaxError = 1;
                        break;
                    }
                    mode = 2;
-                   FILE *fp = fopen(p, "r");
+                   fp = fopen(p, "r");
                    if (fp == NULL) {
                        fprintf(stderr, "Error reading file: %s\n", p);
                        syntaxError = 1;
@@ -444,7 +444,11 @@ void processline(char *line) {
                        syntaxError = 1;
                        break;
                    }
+#ifdef WIN32
+                   version = _strtoui64(p, NULL, 16);
+#else
                    version = strtoull(p, NULL, 16);
+#endif
                    if (version < 0) {
                        syntaxError = 1;
                        break;

+ 3 - 1
src/c/src/zookeeper.c

@@ -3841,6 +3841,9 @@ int flush_send_queue(zhandle_t*zh, int timeout)
     lock_buffer_list(&zh->to_send);
     while (zh->to_send.head != 0&& zh->state == ZOO_CONNECTED_STATE) {
         if(timeout!=0){
+#ifndef WIN32
+            struct pollfd fds;
+#endif
             int elapsed;
             struct timeval now;
             gettimeofday(&now,0);
@@ -3857,7 +3860,6 @@ int flush_send_queue(zhandle_t*zh, int timeout)
             // Poll the socket
             rc = select((int)(zh->fd)+1, NULL,  &pollSet, NULL, &wait);
 #else
-            struct pollfd fds;
             fds.fd = zh->fd;
             fds.events = POLLOUT;
             fds.revents = 0;