Browse Source

[2096] Use void*, not uint8_t*

As we want to make the impression the data is opaque, should not be
examined or pointed into the middle of it.
Michal 'vorner' Vaner 12 years ago
parent
commit
70d316e790

+ 6 - 8
src/lib/datasrc/memory/rdata_reader.cc

@@ -21,7 +21,7 @@ namespace datasrc {
 namespace memory {
 
 RdataReader::RdataReader(const RRClass& rrclass, const RRType& rrtype,
-                         const uint8_t* data,
+                         const void* data,
                          size_t rdata_count, size_t sig_count,
                          const NameAction& name_action,
                          const DataAction& data_action) :
@@ -31,13 +31,11 @@ RdataReader::RdataReader(const RRClass& rrclass, const RRType& rrtype,
     var_count_total_(spec_.varlen_count * rdata_count),
     sig_count_(sig_count),
     spec_count_(spec_.field_count * rdata_count),
-    // The casts, well, C++ decided it doesn't like completely valid
-    // and explicitly allowed cast in C, so we need to fool it through
-    // void.
-    lengths_(static_cast<const uint16_t*>(
-             static_cast<const void*>(data))), // The lenghts are stored first
+    // The lenghts are stored first
+    lengths_(reinterpret_cast<const uint16_t*>(data)),
     // And the data just after all the lengths
-    data_(data + (var_count_total_ + sig_count_) * sizeof(uint16_t)),
+    data_(reinterpret_cast<const uint8_t*>(data) +
+          (var_count_total_ + sig_count_) * sizeof(uint16_t)),
     sigs_(NULL)
 {
     rewind();
@@ -92,7 +90,7 @@ emptyNameAction(const LabelSequence&, unsigned) {
 }
 
 void
-emptyDataAction(const uint8_t*, size_t) {
+emptyDataAction(const void*, size_t) {
     // Do nothing here.
 }
 

+ 3 - 3
src/lib/datasrc/memory/rdata_reader.h

@@ -69,7 +69,7 @@ namespace memory {
 /// void handleName(const dns::LabelSequence& labels, unsigned int flags) {
 ///     ...
 /// }
-/// void handleData(const uint8_t* data, size_t size) {
+/// void handleData(const void* data, size_t size) {
 ///     ...
 /// }
 ///
@@ -87,7 +87,7 @@ public:
     typedef boost::function<void(const dns::LabelSequence&,
                                  RdataNameAttributes)> NameAction;
     /// \brief Function called on each data field in the data.
-    typedef boost::function<void(const uint8_t*, size_t)> DataAction;
+    typedef boost::function<void(const void*, size_t)> DataAction;
 
     /// \brief Constructor
     ///
@@ -104,7 +104,7 @@ public:
     /// \param name_action The callback to be called on each encountered name.
     /// \param data_action The callback to be called on each data chunk.
     RdataReader(const dns::RRClass& rrclass, const dns::RRType& rrtype,
-                const uint8_t* data, size_t rdata_count, size_t sig_count,
+                const void* data, size_t rdata_count, size_t sig_count,
                 const NameAction& name_action, const DataAction& data_action);
 
     /// \brief Result of next() and nextSig()

+ 4 - 3
src/lib/datasrc/memory/tests/rdata_serialization_unittest.cc

@@ -110,7 +110,7 @@ renderNameField(MessageRenderer* renderer, bool additional_required,
 }
 
 void
-renderDataField(MessageRenderer* renderer, const uint8_t* data,
+renderDataField(MessageRenderer* renderer, const void* data,
                 size_t data_len)
 {
     renderer->writeData(data, data_len);
@@ -359,12 +359,13 @@ namespace {
 // a data buffer.
 void
 appendOrRenderData(vector<uint8_t>* where, MessageRenderer** renderer,
-                   const uint8_t* data, size_t size)
+                   const void* data, size_t size)
 {
     if (*renderer != NULL) {
         (*renderer)->writeData(data, size);
     } else {
-        where->insert(where->end(), data, data + size);
+        where->insert(where->end(), reinterpret_cast<const uint8_t*>(data),
+                      reinterpret_cast<const uint8_t*>(data) + size);
     }
 }