Skip to content

Write the minimum signed integer correctly in CSVWriter - #336

Merged
vincentlaucsb merged 2 commits into
vincentlaucsb:masterfrom
youdie006:writer-negative-int-min
Oct 10, 2026
Merged

vincentlaucsb merged 2 commits into
vincentlaucsb:masterfrom
youdie006:writer-negative-int-min

Conversation

@youdie006

@youdie006 youdie006 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

CSVWriter writes INT_MIN as a 20-digit number:

std::stringstream ss;
auto w = csv::make_csv_writer(ss);
w << std::make_tuple(INT_MIN, -1, 7);
// "-18446744071562067968,-1,7"

internals::to_string for signed integers does to_string((size_t)(value * -1)). For the minimum value the negation overflows (UBSan: "negation of -2147483648 cannot be represented in type 'int'" at csv_writer.hpp:132); in practice it wraps back to INT_MIN, and the cast to size_t sign-extends it. long long happens to print right, but UBSan flags LLONG_MIN too. This negates in unsigned arithmetic: "-" + to_string(0ULL - static_cast<unsigned long long>(value)).

Regression tests at the end of tests/test_write_csv.cpp cover -1, INT_MIN, LLONG_MIN, zero, and long long::max(). A public make_csv_writer test writes the extrema in a mixed tuple and checks the complete CSV output. Expected values use standard-library formatting for portability.

Validation: the writer suite passes locally with MSVC on x64 C++20 and x86 C++11. The x86 validation invocation suppresses existing dependency alignment and narrowing warnings; repository build settings are unchanged. Single-include and Emscripten validation are left to CI.

Written with AI assistance (Claude); I have reviewed the change.

to_string for signed integers negated the value before casting it to
size_t, which overflows for INT_MIN: the negation wraps back to INT_MIN
and the cast sign-extends it, so INT_MIN was written as
-18446744071562067968. Negate in unsigned arithmetic instead.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-10T03:48:19.491049Z 258f4d1 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@codecov

codecov Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.54%. Comparing base (4f5b383) to head (267d051).

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #336   +/-   ##
=======================================
  Coverage   91.54%   91.54%           
=======================================
  Files          55       55           
  Lines        3595     3595           
  Branches     1068     1068           
=======================================
  Hits         3291     3291           
  Misses        115      115           
  Partials      189      189           
Flag Coverage Δ
cpp 91.39% <100.00%> (ø)
python 93.64% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 258f4d1e8d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tests/test_write_csv.cpp Outdated
REQUIRE(csv::internals::to_string(-0.666) == "-0.66600");
}

SECTION("Negative Integers") {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Move the regression to the end of the test file

This new Negative Integers section is an edge-case regression, but it is inserted in the opening numeric-converter case ahead of all the mainline writer tests that occupy the rest of the file. Make it a final regression test case so this file preserves the repository's required mainline-first/edge-cases-last organization.

AGENTS.md reference: tests/AGENTS.md:L104-L110

Useful? React with 👍 / 👎.

@vincentlaucsb
vincentlaucsb merged commit eee1732 into vincentlaucsb:master Oct 10, 2026
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants