Skip to content

Commit

Permalink
return int instead of void
Browse files Browse the repository at this point in the history
  • Loading branch information
WillAyd committed Dec 22, 2023
1 parent 7e7351d commit dc1b735
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions c/driver/postgresql/postgres_copy_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -1241,8 +1241,7 @@ class PostgresCopyNumericFieldWriter : public PostgresCopyFieldWriter {
bool truncating_trailing_zeros = true;

char decimal_string[max_decimal_digits_ + 1];
DecimalToString<bitwidth_>(&decimal, decimal_string);
int digits_remaining = std::strlen(decimal_string);
int digits_remaining = DecimalToString<bitwidth_>(&decimal, decimal_string);
do {
const int start_pos = digits_remaining < kDecDigits ?
0 : digits_remaining - kDecDigits;
Expand Down Expand Up @@ -1303,9 +1302,9 @@ class PostgresCopyNumericFieldWriter : public PostgresCopyFieldWriter {
}

private:
// TODO: maybe we should return strlen here
// returns the length of the string
template <int32_t DEC_WIDTH>
void DecimalToString(struct ArrowDecimal* decimal, char* out) {
int DecimalToString(struct ArrowDecimal* decimal, char* out) {
constexpr size_t nwords = (DEC_WIDTH == 128) ? 2 : 4;
uint8_t tmp[DEC_WIDTH / 8];
ArrowDecimalGetBytes(decimal, tmp);
Expand Down Expand Up @@ -1348,9 +1347,11 @@ class PostgresCopyNumericFieldWriter : public PostgresCopyFieldWriter {
p++;
}

const size_t ndigits = sizeof(s) - (p - s);
const size_t ndigits = sizeof(s) - 1 - (p - s);
std::memcpy(out, p, ndigits);
out[ndigits] = '\0';

return ndigits;
}

static constexpr uint16_t kNumericPos = 0x0000;
Expand Down

0 comments on commit dc1b735

Please sign in to comment.