Skip to content

Commit

Permalink
fix warning (conversion from 'uint64_t' to 'std::size_t'), Issue #65,…
Browse files Browse the repository at this point in the history
… and update test program to not require strdup.
  • Loading branch information
greg7mdp committed Jun 19, 2018
1 parent 27c61e7 commit 76c6e00
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion sparsepp/spp_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ inline size_t spp_mix_64(uint64_t a)
a = (a + (a << 2)) + (a << 4); // a * 21
a = a ^ (a >> 28);
a = a + (a << 31);
return a;
return static_cast<size_t>(a);
}

template<class ArgumentType, class ResultType>
Expand Down
14 changes: 11 additions & 3 deletions tests/spp_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ using SPP_NAMESPACE::sparse_hash_set;
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
#ifndef _MSC_VER // windows defines its own version
#define _strdup strdup
#ifdef __MINGW32__ // mingw has trouble writing to /tmp
static std::string TmpFile(const char* basename)
{
Expand Down Expand Up @@ -101,6 +100,15 @@ using SPP_NAMESPACE::sparse_hash_set;
#endif


// ---------------------------------------------------------------------
char *mystrdup(const char *str)
{
size_t len = strlen(str);
char *result = (char *)malloc(len + 1);
memcpy(result, str, len + 1);
return result;
}

// ---------------------------------------------------------------------
// This is the "default" interface, which just passes everything
// through to the underlying hashtable. You'll need to subclass it to
Expand Down Expand Up @@ -951,7 +959,7 @@ struct ValueType
void set_s(const char* new_s) {
if (s_ != kDefault)
free(const_cast<char*>(s_));
s_ = (new_s == NULL ? kDefault : reinterpret_cast<char*>(_strdup(new_s)));
s_ = (new_s == NULL ? kDefault : reinterpret_cast<char*>(mystrdup(new_s)));
}
const char* s() const { return s_; }
private:
Expand Down Expand Up @@ -1184,7 +1192,7 @@ template<> char* UniqueObjectHelper(int index)
if (!g_unique_charstar_objects[static_cast<size_t>(index)]) {
char buffer[64];
snprintf(buffer, sizeof(buffer), "%d", index);
g_unique_charstar_objects[static_cast<size_t>(index)] = _strdup(buffer);
g_unique_charstar_objects[static_cast<size_t>(index)] = mystrdup(buffer);
}
return g_unique_charstar_objects[static_cast<size_t>(index)];
}
Expand Down

0 comments on commit 76c6e00

Please sign in to comment.