[ 
https://issues.apache.org/jira/browse/ARROW-2054?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16345329#comment-16345329
 ] 

ASF GitHub Bot commented on ARROW-2054:
---------------------------------------

wesm closed pull request #1533: ARROW-2054: [C++] Fix compilation warnings
URL: https://github.com/apache/arrow/pull/1533
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/cpp/src/arrow/ipc/json-internal.cc 
b/cpp/src/arrow/ipc/json-internal.cc
index 4088a8f20..204bbc40b 100644
--- a/cpp/src/arrow/ipc/json-internal.cc
+++ b/cpp/src/arrow/ipc/json-internal.cc
@@ -866,7 +866,7 @@ static Status GetField(const rj::Value& obj, const 
DictionaryMemo* dictionary_me
   if (dictionary_memo != nullptr && it_dictionary != json_field.MemberEnd()) {
     // Field is dictionary encoded. We must have already
     RETURN_NOT_OBJECT("dictionary", it_dictionary, json_field);
-    int64_t dictionary_id;
+    int64_t dictionary_id = -1;
     bool is_ordered;
     std::shared_ptr<DataType> index_type;
     RETURN_NOT_OK(ParseDictionary(it_dictionary->value.GetObject(), 
&dictionary_id,
@@ -1346,7 +1346,7 @@ static Status ReadDictionaries(const rj::Value& doc, 
const DictionaryTypeMap& id
 
   for (const rj::Value& val : dictionary_array) {
     DCHECK(val.IsObject());
-    int64_t dictionary_id;
+    int64_t dictionary_id = -1;
     std::shared_ptr<Array> dictionary;
     RETURN_NOT_OK(
         ReadDictionary(val.GetObject(), id_to_field, pool, &dictionary_id, 
&dictionary));
diff --git a/cpp/src/arrow/python/builtin_convert.cc 
b/cpp/src/arrow/python/builtin_convert.cc
index f7a370cdc..e19c42c24 100644
--- a/cpp/src/arrow/python/builtin_convert.cc
+++ b/cpp/src/arrow/python/builtin_convert.cc
@@ -590,6 +590,8 @@ class TimestampConverter
         case TimeUnit::NANO:
           t = PyDateTime_to_ns(pydatetime);
           break;
+        default:
+          return Status::UnknownError("Invalid time unit");
       }
     } else if (PyArray_CheckAnyScalarExact(item.obj())) {
       // numpy.datetime64
diff --git a/cpp/src/arrow/python/io.cc b/cpp/src/arrow/python/io.cc
index 9d32ead52..2cff04608 100644
--- a/cpp/src/arrow/python/io.cc
+++ b/cpp/src/arrow/python/io.cc
@@ -26,6 +26,7 @@
 #include "arrow/io/memory.h"
 #include "arrow/memory_pool.h"
 #include "arrow/status.h"
+#include "arrow/util/logging.h"
 
 #include "arrow/python/common.h"
 
@@ -133,12 +134,14 @@ Status PyReadableFile::Tell(int64_t* position) const {
 
 Status PyReadableFile::Read(int64_t nbytes, int64_t* bytes_read, void* out) {
   PyAcquireGIL lock;
-  PyObject* bytes_obj;
+
+  PyObject* bytes_obj = NULL;
   ARROW_RETURN_NOT_OK(file_->Read(nbytes, &bytes_obj));
+  DCHECK(bytes_obj != NULL);
 
   *bytes_read = PyBytes_GET_SIZE(bytes_obj);
   std::memcpy(out, PyBytes_AS_STRING(bytes_obj), *bytes_read);
-  Py_DECREF(bytes_obj);
+  Py_XDECREF(bytes_obj);
 
   return Status::OK();
 }
@@ -146,11 +149,12 @@ Status PyReadableFile::Read(int64_t nbytes, int64_t* 
bytes_read, void* out) {
 Status PyReadableFile::Read(int64_t nbytes, std::shared_ptr<Buffer>* out) {
   PyAcquireGIL lock;
 
-  PyObject* bytes_obj;
+  PyObject* bytes_obj = NULL;
   ARROW_RETURN_NOT_OK(file_->Read(nbytes, &bytes_obj));
+  DCHECK(bytes_obj != NULL);
 
   *out = std::make_shared<PyBuffer>(bytes_obj);
-  Py_DECREF(bytes_obj);
+  Py_XDECREF(bytes_obj);
 
   return Status::OK();
 }
@@ -172,13 +176,13 @@ Status PyReadableFile::ReadAt(int64_t position, int64_t 
nbytes,
 Status PyReadableFile::GetSize(int64_t* size) {
   PyAcquireGIL lock;
 
-  int64_t current_position;
+  int64_t current_position = -1;
 
   ARROW_RETURN_NOT_OK(file_->Tell(&current_position));
 
   ARROW_RETURN_NOT_OK(file_->Seek(0, 2));
 
-  int64_t file_size;
+  int64_t file_size = -1;
   ARROW_RETURN_NOT_OK(file_->Tell(&file_size));
 
   // Restore previous file position
diff --git a/cpp/src/plasma/fling.cc b/cpp/src/plasma/fling.cc
index 819ec1623..26afd8706 100644
--- a/cpp/src/plasma/fling.cc
+++ b/cpp/src/plasma/fling.cc
@@ -43,7 +43,7 @@ int send_fd(int conn, int fd) {
   header->cmsg_level = SOL_SOCKET;
   header->cmsg_type = SCM_RIGHTS;
   header->cmsg_len = CMSG_LEN(sizeof(int));
-  *reinterpret_cast<int*>(CMSG_DATA(header)) = fd;
+  memcpy(CMSG_DATA(header), reinterpret_cast<void*>(&fd), sizeof(int));
 
   // Send file descriptor.
   ssize_t r = sendmsg(conn, &msg, 0);


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Compilation warnings
> --------------------
>
>                 Key: ARROW-2054
>                 URL: https://issues.apache.org/jira/browse/ARROW-2054
>             Project: Apache Arrow
>          Issue Type: Task
>          Components: C++
>    Affects Versions: 0.8.0
>            Reporter: Antoine Pitrou
>            Priority: Trivial
>              Labels: build, pull-request-available
>             Fix For: 0.9.0
>
>
> I suppose this may vary depending on the compiler, but I get the following 
> warnings with gcc 4.9:
> {code}
> /home/antoine/arrow/cpp/src/plasma/fling.cc: In function ‘int send_fd(int, 
> int)’:
> /home/antoine/arrow/cpp/src/plasma/fling.cc:46:50: warning: dereferencing 
> type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
>    *reinterpret_cast<int*>(CMSG_DATA(header)) = fd;
>                                                   ^
> /home/antoine/arrow/cpp/src/arrow/python/io.cc: In member function ‘virtual 
> arrow::Status arrow::py::PyReadableFile::Read(int64_t, 
> std::shared_ptr<arrow::Buffer>*)’:
> /home/antoine/arrow/cpp/src/arrow/python/io.cc:153:60: warning: ‘bytes_obj’ 
> may be used uninitialized in this function [-Wmaybe-uninitialized]
>    Py_DECREF(bytes_obj);
>                                                             ^
> /home/antoine/arrow/cpp/src/arrow/python/io.cc: In member function ‘virtual 
> arrow::Status arrow::py::PyReadableFile::Read(int64_t, int64_t*, void*)’:
> /home/antoine/arrow/cpp/src/arrow/python/io.cc:141:60: warning: ‘bytes_obj’ 
> may be used uninitialized in this function [-Wmaybe-uninitialized]
>    Py_DECREF(bytes_obj);
>                                                             ^
> /home/antoine/arrow/cpp/src/arrow/python/io.cc: In member function ‘virtual 
> arrow::Status arrow::py::PyReadableFile::GetSize(int64_t*)’:
> /home/antoine/arrow/cpp/src/arrow/python/io.cc:187:20: warning: ‘file_size’ 
> may be used uninitialized in this function [-Wmaybe-uninitialized]
>    *size = file_size;
>                     ^
> /home/antoine/arrow/cpp/src/arrow/python/io.cc:46:65: warning: 
> ‘current_position’ may be used uninitialized in this function 
> [-Wmaybe-uninitialized]
>                               const_cast<char*>(argspec), args...);
>                                                                  ^
> /home/antoine/arrow/cpp/src/arrow/python/io.cc:175:11: note: 
> ‘current_position’ was declared here
>    int64_t current_position;
>            ^
> /home/antoine/arrow/cpp/src/arrow/ipc/json-internal.cc: In function 
> ‘arrow::Status arrow::ipc::internal::json::GetField(const Value&, const 
> arrow::ipc::DictionaryMemo*, std::shared_ptr<arrow::Field>*)’:
> /home/antoine/arrow/cpp/src/arrow/ipc/json-internal.cc:876:81: warning: 
> ‘dictionary_id’ may be used uninitialized in this function 
> [-Wmaybe-uninitialized]
>      RETURN_NOT_OK(dictionary_memo->GetDictionary(dictionary_id, 
> &dictionary));
>                                                                               
>    ^
> /home/antoine/arrow/cpp/src/arrow/ipc/json-internal.cc: In function 
> ‘arrow::Status arrow::ipc::internal::json::ReadSchema(const Value&, 
> arrow::MemoryPool*, std::shared_ptr<arrow::Schema>*)’:
> /home/antoine/arrow/cpp/src/arrow/ipc/json-internal.cc:1354:80: warning: 
> ‘dictionary_id’ may be used uninitialized in this function 
> [-Wmaybe-uninitialized]
>      RETURN_NOT_OK(dictionary_memo->AddDictionary(dictionary_id, dictionary));
>                                                                               
>   ^
> /home/antoine/arrow/cpp/src/arrow/ipc/json-internal.cc:1349:13: note: 
> ‘dictionary_id’ was declared here
>      int64_t dictionary_id;
>              ^
> In file included from /home/antoine/arrow/cpp/src/arrow/api.h:25:0,
>                  from 
> /home/antoine/arrow/cpp/src/arrow/python/builtin_convert.cc:29:
> /home/antoine/arrow/cpp/src/arrow/builder.h: In member function 
> ‘arrow::Status arrow::py::TimestampConverter::AppendItem(const 
> arrow::py::OwnedRef&)’:
> /home/antoine/arrow/cpp/src/arrow/builder.h:284:5: warning: ‘t’ may be used 
> uninitialized in this function [-Wmaybe-uninitialized]
>      raw_data_[length_++] = val;
>      ^
> /home/antoine/arrow/cpp/src/arrow/python/builtin_convert.cc:576:13: note: ‘t’ 
> was declared here
>      int64_t t;
>              ^
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to