libfluent icon indicating copy to clipboard operation
libfluent copied to clipboard

Fix warnings: "warning: 'rc' may be used uninitialized in this function" and "warning: comparison between signed and unsigned integer expressions"

Open flxflndy opened this issue 7 years ago • 1 comments

While compling libfluent with different compiler settings I got two warnings.

`

13-Feb-2018 15:42:09 /data/Libraries/libfluent/src/emitter.cc: In member function 'virtual void fluent::FileEmitter::worker()':
13-Feb-2018 15:42:09 /data/Libraries/libfluent/src/emitter.cc:234:9: warning: 'rc' may be used uninitialized in this function [-Wmaybe-uninitialized]
`

`

13-Feb-2018 15:42:16 /data/Libraries/libfluent/tools/fluent-bench.cc: In function 'int main(int, char**)':
13-Feb-2018 15:42:16 /data/Libraries/libfluent/tools/fluent-bench.cc:68:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
13-Feb-2018 15:42:16 int diff = (mps > msg_count) ? mps - msg_count : msg_count - mps;
13-Feb-2018 15:42:16 ^
13-Feb-2018 15:42:16 /data/Libraries/libfluent/tools/fluent-bench.cc:75:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
13-Feb-2018 15:42:16 if (mps < msg_count) {
13-Feb-2018 15:42:16 ^
13-Feb-2018 15:42:16 /data/Libraries/libfluent/tools/fluent-bench.cc:77:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
13-Feb-2018 15:42:16 } else if (mps > msg_count) {
`
The following changes fixes the issues.
diff --git a/Libraries/libfluent/src/emitter.cc b/Libraries/libfluent/src/emitter.cc
index 28fb5fb..e533b81 100644
--- a/Libraries/libfluent/src/emitter.cc
+++ b/Libraries/libfluent/src/emitter.cc
@@ -212,7 +212,7 @@ namespace fluent {
     Message *root;
     while (nullptr != (root = this->queue_.bulk_pop())) {
       for(Message *msg = root; msg; msg = msg->next()) {
-        int rc;
+        int rc = 0;
         switch(this->format_) {
           case MsgPack: {
             msgpack::sbuffer buf;


diff --git a/Libraries/libfluent/tools/fluent-bench.cc b/Libraries/libfluent/tools/fluent-bench.cc
index dcc98c8..6ab8ef6 100644
--- a/Libraries/libfluent/tools/fluent-bench.cc
+++ b/Libraries/libfluent/tools/fluent-bench.cc
@@ -46,7 +46,7 @@ int main(int argc, char *argv[]) {

   int wait = 1000000 / mps;
   time_t last_ts = time(nullptr);
-  size_t msg_count = 0;
+  int msg_count = 0;

   std::cout << "wait: " << wait << "usec" << std::endl;

Best regards,

flxflndy avatar Feb 13 '18 15:02 flxflndy

Thank you for reporting the issue. Let me check it and fix it in next weekend.

m-mizutani avatar Feb 16 '18 07:02 m-mizutani