Skip to content

feat(libcurl): implement buffer curl_m*printf over guest va_list - #17390

Open
ThorstenFR-Cyber wants to merge 13 commits into
boykopovar:mainfrom
ThorstenFR-Cyber:feat/libcurl-mprintf-buffers
Open

ThorstenFR-Cyber wants to merge 13 commits into
boykopovar:mainfrom
ThorstenFR-Cyber:feat/libcurl-mprintf-buffers

Conversation

@ThorstenFR-Cyber

Copy link
Copy Markdown

What

Implements curl_mvsnprintf, curl_msnprintf, curl_mvsprintf, curl_msprintf, curl_mvaprintf and curl_maprintf, which threw through NotImplemented_nid_no_patch. libcurl goes from 56/85 to 62/85.

The host libcurl cannot format guest arguments. On a MinGW host long is 32 bits, the guest va_list is SysV, and curl's mprintf.c enables the I32/I64 qualifiers under __MINGW32__. src/CurlFormat.cpp ports both passes of lib/mprintf.c from curl tag curl-7_81_0 (the submodule's source) with LP64 sizes and no I32/I64:

  • l, z and O read 8 bytes;
  • %n, %hn and %ln write 4, 2 and 8 bytes through GuestCopyOut_nid_no_patch;
  • arguments are read from the guest SysV va_list with LibcDetail::FormatArguments, and the caller's list is left unchanged.

These follow curl's code: positional parameters, * widths and precisions, (nil) for NULL strings and pointers, %S quoting, the 128-parameter limit (-1), the return value of msnprintf (characters stored, not the would-be length), and the aprintf result limit (DYN_APRINTF, 8000000) returning NULL. aprintf results come from the guest heap and are released with curl_free.

Floating-point conversions build the same %[flags][width][.prec][l]f|e|g string as curl and format it with the guest snprintf instead of the console sprintf.

Inputs whose behaviour in curl is undefined throw instead. They are listed in a new Formatting entry in docs/dev/debt/libcurl.md:

  • an argument position no conversion describes (uninitialised va_stack);
  • more than 128 conversions (endpos overflow);
  • a floating-point result longer than the 326-byte work buffer;
  • a %n destination that is not writable guest memory.

The FILE and stdout variants (curl_m[v]printf, curl_m[v]fprintf) remain stubs for a follow-up PR.

Tested

Windows 11, WinLibs GCC 15.2.0 x86_64-ucrt-posix-seh r7, full build plus libs.

  • ctest --test-dir build -R guest_curl --output-on-failure: 9/9 passed. On main, the 8 existing tests also pass.
  • The new guest_curl_format test covers:
    • integer flags, widths and precisions; 64-bit %ld/%lu/%lld/%zu/%lx/%qd; %d reading the low 32 bits of a slot;
    • %c, strings and NULL; pointers and NULL; %%; a conversion curl does not know that still consumes its argument;
    • positional and * arguments, including negative widths;
    • floats interleaved with integers;
    • %n of three sizes;
    • truncation, size 0, and %n after truncation;
    • the 129-conversion error in all three families;
    • the v* entry points with an unchanged guest va_list;
    • maprintf at and above the 8000000-byte limit.
  • Changing one expected value makes the test abort.
  • tools/check_conventions.py --base upstream/main passed. tools/check_test_registration.py build passed. core/libs/tests/test_public_headers.py --audit-only passed.
  • tools/progress.py --module libcurl reports 56/85 before and 62/85 after.
  • tools/pr_overlap.py: it could not compare docs(debt): separate entries with blank lines and drop derived export totals #14212 (blank-line reformat of the debt files, already conflicting with main). That PR does not touch these functions.
  • Linux and console output: not tested.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

Port the two passes of curl 7.81.0 lib/mprintf.c with LP64 argument
sizes and without the Windows I32/I64 qualifiers, reading arguments
from the guest SysV va_list. Floating-point conversions go through
the guest snprintf.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@gabichuuuuu gabichuuuuu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Windows run of head 391ecdce76, merged onto main 095ff72367. To save builds, this ran in one tree together with 24 other open PRs that touch different code; all 25 merged cleanly. Setup: Windows 11, WinLibs GCC 15.2 (x86_64-ucrt-posix-seh), Release, BUILD_TESTING=ON.

  • guest_curl_format with --repeat until-fail:5: 5 / 5 pass.
  • No negative control: on main these six exports throw NotImplemented.
  • Differential check against curl itself, not part of this PR. I linked a test against both this PR's curl_msnprintf_nid_postfix and the host build of the bundled curl 7.81 (3rdparty/curl, lib/mprintf.c), and fed both the same arguments. There were 200,000 random formats, each with an int conversion (d i u x X o c), an ll conversion, a floating conversion (f e E g G), %s (including null) and %p, with random -+ #0 flags, widths 0-12 and precisions 0-10, literal text and %% between them, and output sizes of 0-11 or 256. Every result and buffer matches, including truncation, (nil) and the #/0 combinations.

The only differences come with floating values that end exactly on a tie or need more than 17 digits: %.0f of 2.5 is 3 here and 2 in the host curl, and %f of 1e100 keeps 17 exact digits. That isn't this PR. The values go through the guest snprintf, which deliberately formats as the titles' libc.prx does (docs/dev/debt/libc.md, the "%e, %f and %g" entry). On the console, curl's mprintf would get the same digits from that libc.prx, so going through the guest snprintf is the right choice. The debt entry could say so, so the difference from a host build of curl isn't mistaken for a bug.

@JJenkx

JJenkx commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

Windows check of head 391ecdce76, merged onto main 095ff72367 (c280c08e4b, clean merge).

Setup: Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release. The hosted Windows check does not run these tests on pull requests.

  • All 9 guest_curl* tests pass in 3 of 3 runs, none skipped: guest_curl, guest_curl_strings, guest_curl_utility, guest_curl_url, guest_curl_slistmime, guest_curl_options, guest_curl_handles, guest_curl_transfers and the new guest_curl_format.
  • The curl_m*printf exports read the guest's arguments through __builtin_sysv_va_list, which is what makes them work on Windows. A host va_list there would misread the System V layout.

AI-assisted: yes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ThorstenFR-Cyber

Copy link
Copy Markdown
Author

@gabichuuuuu
Thanks for the differential check. As suggested, I added a sentence to the Formatting entry in docs/dev/debt/libcurl.md (7f12ced). It says floating-point digits follow the libc %e, %f and %g entry, which is what the console's curl gets from libc.prx. It also says they differ from a host build of curl on exact ties and past 17 significant digits, with the %.0f of 2.5 example. The commit only changes the docs, and the code is the same as 391ecdc.

CurlFormat.cpp ports both passes of lib/mprintf.c from curl tag curl-7_81_0, so it now starts with that file's copyright and licence header, unchanged.
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Nov 12, 2026
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 13, 2026
Luis Meireles and others added 4 commits November 13, 2026 23:24
…he merge

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
curl_global_init_mem now selects the guest callbacks curl_free releases
through, so the aprintf buffer grows with Curl_crealloc as Curl_dyn_addn
does, frees through Curl_cfree on failure and duplicates the empty result
with Curl_cstrdup, as curl 7.81.0's curl_mvaprintf does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@LeandroLP23

Copy link
Copy Markdown
Contributor

A suggestion for the tests, from a port of the same mprintf.c I wrote before I saw this PR (I won't open mine). The test topics can link anyps5_curl_backend, as Transfers and MimeCallback already do. That makes the host build of curl's real curl_msnprintf available as an oracle, so the formatter can be checked differentially instead of only against handwritten strings:

template<typename... T> void Oracle(const char* format, T... arguments) {
    for (std::size_t size : {0, 1, 7, 256}) {
        char host[256], guest[256];
        std::memset(host, 'x', sizeof(host));
        std::memset(guest, 'x', sizeof(guest));
        const int expected = curl_msnprintf(host, size, format, arguments...);
        const int actual = curl_msnprintf_nid_postfix(guest, size, format, arguments...);
        Require(expected == actual && std::memcmp(host, guest, sizeof(host)) == 0);
    }
}

This only holds for formats that don't depend on long width or the MinGW I64 extension, because the host build is LLP64. For %ld, %zu and floating point, handwritten expectations still apply.

Cases that caught mistakes in mine, in case they are useful here:

  • buffer sizes 0 and 1, for the return value and termination;
  • %#.0o with 0;
  • %3$*1$.*2$d;
  • %129$d, which is not positional and becomes width 129;
  • a curl_maprintf result of exactly 7999999 characters, which fits, against 8000000, which fails dynbuf's limit;
  • %n, %ln, %hn and %lln after a known prefix.

AI-assisted: yes (Claude Code)

@Ducengarth

Copy link
Copy Markdown
Contributor

Independent check on Windows, with an oracle test written separately from this PR.

Setup. Windows 11 Pro 10.0.26300 and WinLibs GCC 15.2.0, Release build, main at e49aca7877. I made two runs:

What the test covers. It links anyps5_curl_backend and compares curl_msnprintf_nid_postfix with the host build of curl 7.81.0's own curl_msnprintf, byte for byte and return value included, on about 40 formats. Where host and guest sizes differ, it checks fixed values instead:

  • Oracle formats: flags, widths and precisions, * and .* with negative values, %hd, %S and %#s, NULL %s with and without precision, %p and NULL %p, %f/%e/%g with flags, %.400f and %400.300f (precision clamping), positional and repeated parameters, %2$*1$d, an unknown conversion, a trailing %, and 65 %*d (the parameter limit, so -1).
  • LP64 sizes: %ld, %lu, %lx, %zu, %zd, %Od, %lld and %qd with 64-bit values.
  • I conversion: %I64d gives 64d, because I is a conversion of its own without MinGW's extensions.
  • %n widths: %n, %hn, %ln and %lln store 4, 2, 8 and 8 bytes.
  • Buffers: truncation at sizes 0, 1, 5 and an exact fit; curl_msprintf, including its terminator after a parse failure; curl_maprintf with an empty result, a parse failure, 7,999,999 characters and the 8,000,000-byte dynbuf limit; curl_mfprintf through a guest stream.

The test also catches errors: in a separate port of mprintf.c I wrote for comparison, replacing (nil) with (null), or storing %ln in 4 bytes, makes it fail.

Two inputs are undefined in curl 7.81.0, and this PR may want to decide them explicitly; neither is tested above:

  • A precision with +inf loops forever in dprintf_formatf's while(val >= 10.0).
  • A positional parameter below the highest one that no conversion uses leaves vto[i] uninitialised in dprintf_Pass1.
tests/CurlPrintf.cpp (topic Printf, linked with anyps5_curl_backend)
#include "prx/libcurl/src/CurlHost.hpp"
#include "prx/libcurl/libcurl.hpp"
#include "prx/libc/include/ApplicationHeap.hpp"
#include "prx/libc/include/Api.hpp"

#include <array>
#include <climits>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <filesystem>
#include <string>

namespace {

void Require(bool condition, const char* message) {
    if (condition) return;
    std::fprintf(stderr, "curl printf check failed: %s\n", message);
    std::abort();
}

template <class... Arguments>
void Same(const char* format, Arguments... arguments) {
    std::array<char, 512> guest{};
    std::array<char, 512> host{};
    guest.fill('G');
    host.fill('G');
    const int guestResult = curl_msnprintf_nid_postfix(guest.data(), guest.size(), format, arguments...);
    const int hostResult = curl_msnprintf(host.data(), host.size(), format, arguments...);
    if (guestResult != hostResult || guest != host) {
        std::fprintf(stderr, "format \"%s\": guest %d \"%s\", curl %d \"%s\"\n", format, guestResult, guest.data(), hostResult, host.data());
        std::abort();
    }
}

std::string Guest(const char* format, std::int64_t value) {
    std::array<char, 128> buffer{};
    const int result = curl_msnprintf_nid_postfix(buffer.data(), buffer.size(), format, value);
    Require(result == static_cast<int>(std::strlen(buffer.data())), "the result counts the stored characters");
    return buffer.data();
}

void CheckMatchesCurl() {
    Same("plain text");
    Same("%%");
    Same("100%% %d", 5);
    Same("%d", 42);
    Same("%d", -42);
    Same("%i", INT_MIN);
    Same("%u", 3000000000u);
    Same("%x %X", 0xbeefu, 0xbeefu);
    Same("%o %#o %#o", 8u, 8u, 0u);
    Same("%#x %#X %#x", 255u, 255u, 0u);
    Same("%c%5c|%-5c|", 'A', 'B', 'C');
    Same("%5d|%-5d|%05d|%-05d|", 42, 42, -42, 42);
    Same("%+d % d %+d", 42, 42, -42);
    Same("%.3d %.0d %8.3d|", 7, 0, -7);
    Same("%*d|%*d|", 6, 42, -6, 42);
    Same("%.*d %.*d", 4, 42, -1, 42);
    Same("%-*.*d|", 8, 4, 42);
    Same("%hd %hu", 70000, 70000);
    Same("%s|%10s|%-10s|%.2s|", "text", "text", "text", "text");
    Same("%S %#s %#10s|", "text", "text", "text");
    Same("%s|%.3s|%.5s|%10s|%#s", static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), static_cast<const char*>(nullptr), static_cast<const char*>(nullptr));
    Same("%p %10p| %-10p|", reinterpret_cast<void*>(0x1234), static_cast<void*>(nullptr), static_cast<void*>(nullptr));
    Same("%f %.2f %e %E", 3.25, 3.14159, 12345.678, 0.000123);
    Same("%g %G %#g %+f", 0.0001, 1e20, 1.0, 1.0);
    Same("%10.3f|%-10.3f|%*.*f|", -2.5, 2.5, 12, 3, 3.14159);
    Same("%*f|%.*f", -9, 1.5, -2, 1.5);
    Same("%.400f", 1.5);
    Same("%400.300f|", 123.25);
    Same("%2$s %1$s", "first", "second");
    Same("%1$s %1$s %2$d", "same", 3);
    Same("%2$*1$d|", 6, 42);
    Same("%d %s %f %c", 1, "x", 2.5, 'y');
    Same("%k|", static_cast<void*>(nullptr));
    Same("abc%", static_cast<void*>(nullptr));
    std::string tooMany;
    for (int index = 0; index < 65; ++index) tooMany += "%*d";
    Same(tooMany.c_str());
}

void CheckGuestSizes() {
    Require(Guest("%ld", 0x123456789LL) == "4886718345", "%ld reads a 64-bit long");
    Require(Guest("%ld", INT64_MIN) == "-9223372036854775808", "%ld prints the 64-bit minimum");
    Require(Guest("%lu", -1) == "18446744073709551615", "%lu reads a 64-bit unsigned long");
    Require(Guest("%lx", 0x1122334455667788LL) == "1122334455667788", "%lx reads 64 bits");
    Require(Guest("%zu", 0x10000000000LL) == "1099511627776", "%zu reads a 64-bit size_t");
    Require(Guest("%zd", -1) == "-1", "%zd is a signed long");
    Require(Guest("%Od", 0x7000000000000000LL) == "8070450532247928832", "%Od reads a curl_off_t");
    Require(Guest("%lld", INT64_MAX) == "9223372036854775807", "%lld reads a long long");
    Require(Guest("%qd", -5) == "-5", "%qd reads a long long");
    Require(Guest("%I64d", 7) == "64d", "I is a conversion of its own on the console, not a size");

    std::array<unsigned char, 16> counts{};
    std::array<char, 32> buffer{};
    counts.fill(0xee);
    Require(curl_msnprintf_nid_postfix(buffer.data(), buffer.size(), "abc%n", counts.data()) == 3, "%n output");
    Require(counts[0] == 3 && counts[1] == 0 && counts[3] == 0 && counts[4] == 0xee, "%n stores four bytes");
    counts.fill(0xee);
    curl_msnprintf_nid_postfix(buffer.data(), buffer.size(), "abcd%ln", counts.data());
    Require(counts[0] == 4 && counts[7] == 0 && counts[8] == 0xee, "%ln stores a 64-bit long");
    counts.fill(0xee);
    curl_msnprintf_nid_postfix(buffer.data(), buffer.size(), "ab%hn", counts.data());
    Require(counts[0] == 2 && counts[1] == 0 && counts[2] == 0xee, "%hn stores two bytes");
    counts.fill(0xee);
    curl_msnprintf_nid_postfix(buffer.data(), buffer.size(), "a%lln", counts.data());
    Require(counts[0] == 1 && counts[7] == 0 && counts[8] == 0xee, "%lln stores eight bytes");
}

void CheckBuffers() {
    std::array<char, 16> buffer{};
    buffer.fill('x');
    Require(curl_msnprintf_nid_postfix(buffer.data(), 5, "abcdefgh") == 4, "a full buffer drops the last stored character");
    Require(std::strcmp(buffer.data(), "abcd") == 0 && buffer[5] == 'x', "a full buffer keeps four characters and a terminator");
    buffer.fill('x');
    Require(curl_msnprintf_nid_postfix(buffer.data(), 9, "abcdefgh") == 8 && std::strcmp(buffer.data(), "abcdefgh") == 0, "an exact fit keeps every character");
    buffer.fill('x');
    Require(curl_msnprintf_nid_postfix(buffer.data(), 0, "abc") == 0 && buffer[0] == 'x', "a zero size writes nothing");
    Require(curl_msnprintf_nid_postfix(buffer.data(), 1, "abc") == 0 && buffer[0] == '\0', "a size of one stores only the terminator");
    std::string tooMany;
    for (int index = 0; index < 65; ++index) tooMany += "%*d";
    buffer.fill('x');
    Require(curl_msnprintf_nid_postfix(buffer.data(), buffer.size(), tooMany.c_str()) == -1 && buffer[0] == 'x', "a parameter past 128 fails without output");

    buffer.fill('x');
    Require(curl_msprintf_nid_postfix(buffer.data(), "%s-%d", "a", 5) == 3 && std::strcmp(buffer.data(), "a-5") == 0, "curl_msprintf");
    buffer.fill('x');
    Require(curl_msprintf_nid_postfix(buffer.data(), tooMany.c_str()) == -1 && buffer[0] == '\0', "curl_msprintf terminates even when parsing fails");

    char* text = curl_maprintf_nid_postfix("%s=%d", "key", 7);
    Require(text && std::strcmp(text, "key=7") == 0, "curl_maprintf");
    curl_free(text);
    text = curl_maprintf_nid_postfix("");
    Require(text && text[0] == '\0', "an empty curl_maprintf result is an empty string");
    curl_free(text);
    Require(curl_maprintf_nid_postfix(tooMany.c_str()) == nullptr, "curl_maprintf returns null when parsing fails");
    text = curl_maprintf_nid_postfix("%7999999s", "");
    Require(text && std::strlen(text) == 7999999, "curl_maprintf keeps 7999999 characters");
    curl_free(text);
    Require(curl_maprintf_nid_postfix("%8000000s", "") == nullptr, "curl_maprintf stops at the 8000000-byte dynamic buffer limit");
}

void CheckStreams() {
    const auto path = (std::filesystem::temp_directory_path() / "anyps5-curl-printf.txt").string();
    FileStream* stream = fopen_nid_postfix(path.c_str(), "w+");
    Require(stream != nullptr, "open a guest stream");
    Require(curl_mfprintf_nid_postfix(reinterpret_cast<std::FILE*>(stream), "%d-%s|", 5, "x") == 4, "curl_mfprintf counts its characters");
    rewind_nid_postfix(stream);
    std::array<char, 16> read{};
    Require(fread_nid_postfix(read.data(), 1, read.size(), stream) == 4 && std::memcmp(read.data(), "5-x|", 4) == 0, "curl_mfprintf writes through the guest stream");
    fclose_nid_postfix(stream);
    std::filesystem::remove(path);
}

}

int main() {
    ApplicationHeapInitialize_nid_no_patch(ApplicationEmptyProcessParameters_nid_no_patch());
    CheckMatchesCurl();
    CheckGuestSizes();
    CheckBuffers();
    CheckStreams();
    std::puts("curl printf tests passed");
    return 0;
}

AI-assisted: yes.

Luis Meireles and others added 3 commits November 14, 2026 20:20
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ThorstenFR-Cyber

Copy link
Copy Markdown
Author

Thanks @LeandroLP23 and @Ducengarth for the independent checks. I pushed three commits on top of 5f30dd78dc.

  • fix(libcurl): stop the float precision clamp looping on infinity. %.2f of +inf hung in the digit-count loop that runs before the precision clamp, same as curl 7.81.0. curl 8.22.0 bounds that loop with maxprec (282057f32a, mprintf: avoid never-ending loop for positive-infinite curl/curl#22713), but in the 7.81.0 port maxprec is a size_t and wraps once the width is clamped to 325, so %400.2f of +inf still hung. The loop is now also skipped for non-finite values. Precision has no effect on how inf and nan print, so the output matches 8.22.0. The test covers +inf, -inf and NaN, with and without precision and width.
  • fix(libcurl): throw on a width or precision argument that is never read. In curl 7.81.0 a width or precision that names its own conversion (%*1$d, %1$*1$d) is never read, so curl prints an uninitialised va_stack slot. The port printed 0. It now throws, as it already did for an argument position nothing reads (%3$d %1$d, now tested too). %1$*2$d %2$d, where position 2 is read twice, still formats as curl does ( 5 3 for 9, 5, 3).
  • test(libcurl): pin five curl 7.81.0 formatting quirks. The cases are %06.3d, %#x|%#.0x|%.0d with 0, %1$*2$d, %o of -1, and %129$d. curl parses the last one as a width followed by an unknown $ conversion and prints d. The expected strings come from the host build of curl 7.81.0's curl_msnprintf.

On the oracle suggestion: I ran the port against the host curl 7.81.0 curl_msnprintf on about 30 formats outside the PR, and every result matched. I left the oracle out of the test suite because linking anyps5_curl_backend into the Format test would change the build. The cases it found are handwritten in tests/CurlFormat.cpp.

Tested on Windows 11, WinLibs GCC 15.2.0, Release: all 11 guest_curl* tests pass in 3 runs out of 3. On 5f30dd78dc the infinity test times out and the self-referencing width cases fail.

AI-assisted: yes.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Nov 15, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Nov 16, 2026
@Lancito01

Copy link
Copy Markdown
Contributor

I cross-checked this PR's formatter (a30a3287c4) against the curl 7.81.0 backend from 3rdparty/curl and against an independent port of lib/mprintf.c, on Windows 11 with WinLibs GCC 15.2. About 6,100 inputs went through FormatBounded at buffer sizes 512, 7 and 1. They covered integer, string, pointer and positional conversions, * widths and precisions, flag combinations, unknown conversions and doubles.

  • Every input with defined behaviour matched the backend byte for byte, including the return value.
  • Doubles differ from the Windows host backend only as the debt entry describes: ties, digits past the 17th, and -nan against -nan(ind).
  • %1$*1$d throws here, while the backend printed 0. That 0 comes from curl's uninitialised vto[] (FORMAT_WIDTH is converted to FORMAT_INT without reading an argument), so throwing looks right.

No issues found.


Co-authored with Claude Code

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed — changes requested

Changes are required before merge: handle negative * widths for floating-point conversions as left-justified fields.

What I ran

Reviewed head a30a3287c49b9854d56d43fe99aa8a6409e2c4ba using the prepared diff and repo_read.py source reader. No commands or tests were run.

Results

Check Result Note
Code review failed Negative float width is dropped
Tests not run Author reports Windows tests passed

Findings

Blocking

  • core/libs/prx/libcurl/src/CurlFormat.cpp:774-776: For a floating conversion with a negative * width, floating() only appends a width when it is nonnegative, but does not set left alignment. Thus a format such as %*f with width -8 is formatted without the requested field width or left justification. Normalize negative dynamic float widths to positive width and apply the left flag, as the integer conversion path does.

Non-blocking

None.

Not verified

No tests were run. The changed files core/libs/prx/libcurl/CMakeLists.txt, core/libs/prx/libcurl/Export.cpp, core/libs/prx/libcurl/src/CurlFormat.cpp, core/libs/prx/libcurl/src/CurlFormat.hpp, core/libs/prx/libcurl/tests/CurlFormat.cpp, and docs/dev/debt/libcurl.md were present in the review bundle; the implementation, API wiring, and tests were read. The complete text of Export.cpp, CMake configuration, and debt documentation was not read. Linux and console behavior were not verified. The author's reported test results were not independently run.

To get this to a good state

Handle negative dynamic widths in floating conversions and add coverage for %*f with a negative width. Rerun the reported guest_curl tests on the new head.

@oneandonlydean
oneandonlydean dismissed MarcZX10’s stale review November 25, 2026 21:31

Checked at a30a328 against the upstream file this port names, curl lib/mprintf.c at 801bd5138ce31aa0d906fa4e2eabfc599d74e793. Upstream formatf turns a negative '*' width into FLAGS_LEFT plus a positive local width, but its FORMAT_DOUBLE branch re-reads the width from vto[p->width], which still holds the negative value, and appends a width only if(width >= 0). So upstream formats %*f with -8 as %-f: left flag, no width. CurlFormat.cpp does the same (shared width resolution at lines 278 to 285, floating() at 674 to 690), so the port matches the library it reproduces.

@MertCtn MertCtn 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.

Nit on the [Formatting] debt entry: sibling entries link the pinned upstream source (e.g. easy.c, formdata.c), but this one says follow `lib/mprintf.c` of curl 7.81.0 without a link. Suggested:

- follow `lib/mprintf.c` of curl 7.81.0 with LP64 argument sizes
+ follow pinned [lib/mprintf.c](https://github.com/curl/curl/blob/801bd5138ce31aa0d906fa4e2eabfc599d74e793/lib/mprintf.c) with LP64 argument sizes

(That SHA is the checked-in 3rdparty/curl submodule commit, and lib/mprintf.c exists there.)

Note the link pushes the entry over the 1000-char debt-length limit (969 chars now), so something small has to give to stay under it — e.g. through the guest → with the guest plus dropping the , which the console's curl also gets from libc.prx`` clause lands at 996 chars with no gap statement lost. Happy to post the exact one-line replacement if useful.

Verified locally: debt_fold.py --check passes, check_conventions.py scoped to the one-line debt change passes, and the full guest_curl suite (13/13, including guest_curl_format) passes on the 18468 stack containing this commit.

@ligmaSec ligmaSec 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.

Please move the debt changes into a fragment and add a permalink to the pinned upstream source in the CurlFormat.cpp attribution. The source currently gives the commit hash while the debt edits go straight into docs/dev/debt/libcurl.md.

I ran guest_curl_format on Linux with the patch applied. It passed the buffer, allocation, and guest argument-formatting fixtures.

AI-assisted: yes.

@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 24542 core/libs/prx/libcurl/Export.cpp

@THEMANnt THEMANnt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

On the negative dynamic width finding above: the pinned curl 7.81.0 formatter rereads the raw width in FORMAT_DOUBLE and emits a numeric width only when that value is nonnegative. This PR does the same. I would keep the curl behavior unless guest measurements show a difference, and add this case to the existing backend comparison fixture so the intended result stays explicit.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.