[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [lmi] expand_html() msw64: 'SIZE_MAX <= index' always false
From: |
Greg Chicares |
Subject: |
Re: [lmi] expand_html() msw64: 'SIZE_MAX <= index' always false |
Date: |
Sun, 24 Mar 2019 21:27:27 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 |
On 2019-03-24 20:41, Vadim Zeitlin wrote:
> On Sun, 24 Mar 2019 19:18:17 +0000 Greg Chicares <address@hidden> wrote:
[...string manipulation with std::strtoul()...]
> GC> I figured that you had chosen SIZE_MAX because you wanted type
> std::size_t,
> GC> much as we compare std::string::find() results to std::string::npos.
>
> But find() is documented to return npos, while std::strtoul() is
> documented to return ULONG_MAX in case of overflow. And I [know that I]
> know it. So this can't be the explanation -- but the commit 416ab02f that
> you have so obligingly found for me does provide one:
>
> In this commit, the check preceded a static_cast of index to size_t, so
> I must have just decided to make it absolutely manifest that the cast was
> valid and didn't realize that this could result in the problem when
> ULONG_MAX < SIZE_MAX.
Without looking at the history, I'll assume that I saw std::size_t
and naturally vaporized it without a second thought, presumably
without replacing SIZE_MAX. If so, I didn't miss any other occurrence:
/opt/lmi/src/lmi[0]$grep --quiet SIZE_MAX *.?pp || echo "no occurrences found"
no occurrences found
so the mystery has been resolved and everything's now okay.
But why use that C function anyway, instead of std::stringstream?
Granted, std::string and std::stringstream aren't as good as they
could be if they were redesigned today, but OTOH when I examine:
/opt/lmi/src/lmi[0]$grep strto *.?pp |less -S
I see your comment here (which I heartily agree with):
rate_table.cpp:// Helper function wrapping std::strtoull() and hiding its
peculiarities:
and great pains are taken in 'numeric_io_*.?pp' to hide those same
peculiarities; this
pdf_command_wx.cpp: auto const index = std::strtoul(s.c_str() + open_pos +
1, &stop, 10);
is the only line that uses any of these functions directly.