Skip to content

Commit

Permalink
handle strict-aliasing
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroshade committed Nov 15, 2024
1 parent 29487c5 commit 7105801
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/nanoarrow/common/inline_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ static inline void ArrowDecimalInit(struct ArrowDecimal* decimal, int32_t bitwid
/// to 18 is sufficiently small).
static inline int64_t ArrowDecimalGetIntUnsafe(const struct ArrowDecimal* decimal) {
if (decimal->n_words == 0) {
return ((int32_t*)decimal->words)[0];
return (int32_t)decimal->words[0];
}
return (int64_t)decimal->words[decimal->low_word_index];
}
Expand All @@ -954,7 +954,7 @@ static inline void ArrowDecimalGetBytes(const struct ArrowDecimal* decimal,
/// \ingroup nanoarrow-utils
static inline int64_t ArrowDecimalSign(const struct ArrowDecimal* decimal) {
if (decimal->n_words == 0) {
return 1 | (((int32_t*)decimal->words)[0] >> 31);
return 1 | ((int32_t)decimal->words[0] >> 31);
}

return 1 | ((int64_t)(decimal->words[decimal->high_word_index]) >> 63);
Expand All @@ -964,7 +964,7 @@ static inline int64_t ArrowDecimalSign(const struct ArrowDecimal* decimal) {
/// \ingroup nanoarrow-utils
static inline void ArrowDecimalSetInt(struct ArrowDecimal* decimal, int64_t value) {
if (decimal->n_words == 0) {
((int32_t*)decimal->words)[0] = (int32_t)value;
decimal->words[0] = (int32_t)value;
return;
}

Expand All @@ -981,7 +981,7 @@ static inline void ArrowDecimalSetInt(struct ArrowDecimal* decimal, int64_t valu
/// \ingroup nanoarrow-utils
static inline void ArrowDecimalNegate(struct ArrowDecimal* decimal) {
if (decimal->n_words == 0) {
((int32_t*)decimal->words)[0] = -((int32_t*)decimal->words)[0];
decimal->words[0] = -(int32_t)decimal->words[0];
return;
}

Expand Down Expand Up @@ -1009,7 +1009,7 @@ static inline void ArrowDecimalNegate(struct ArrowDecimal* decimal) {
static inline void ArrowDecimalSetBytes(struct ArrowDecimal* decimal,
const uint8_t* value) {
if (decimal->n_words == 0) {
memcpy(decimal->words, value, sizeof(int32_t));
memcpy(decimal->words + sizeof(int32_t), value, sizeof(int32_t));
} else {
memcpy(decimal->words, value, decimal->n_words * sizeof(uint64_t));
}
Expand Down

0 comments on commit 7105801

Please sign in to comment.