You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Yann Ylavic <yl...@gmail.com> on 2018/07/23 22:33:29 UTC
Re: svn commit: r1836519 - /apr/apr/trunk/strings/apr_strings.c
On Tue, Jul 24, 2018 at 12:28 AM, <ni...@apache.org> wrote:
>
> @@ -387,18 +389,20 @@ APR_DECLARE(char *) apr_ltoa(apr_pool_t
> char *buf = apr_palloc(p, BUFFER_SIZE);
> char *start = buf + BUFFER_SIZE - 1;
> int negative;
> + unsigned int un;
unsigned long for ltoa?
> if (n < 0) {
> negative = 1;
> - n = -n;
> + un = -n;
> }
> else {
> negative = 0;
> + un = n;
> }
> *start = 0;
> do {
> - *--start = (char)('0' + (n % 10));
> - n /= 10;
> - } while (n);
> + *--start = (char)('0' + (un % 10));
> + un /= 10;
> + } while (un);
> if (negative) {
> *--start = '-';
> }
Regards,
Yann.
Re: svn commit: r1836519 - /apr/apr/trunk/strings/apr_strings.c
Posted by Nick Kew <ni...@apache.org>.
> On 25 Aug 2018, at 14:55, Rainer Jung <ra...@kippdata.de> wrote:
>
> Should this be changed or reverted? The discussion seems to have stalled.
Damn, did something half-baked get committed?
> And what about backport for 1.7.x and 1.6.x?
IMHO not for 1.6: keep changes really minimal. 1.7 would make sense.
--
Nick Kew
Re: svn commit: r1836519 - /apr/apr/trunk/strings/apr_strings.c
Posted by Rainer Jung <ra...@kippdata.de>.
Should this be changed or reverted? The discussion seems to have stalled.
And what about backport for 1.7.x and 1.6.x?
Regards,
Rainer
Am 24.07.2018 um 17:42 schrieb Yann Ylavic:
> On Tue, Jul 24, 2018 at 12:53 AM, William A Rowe Jr <wr...@rowe-clan.net> wrote:
>> I'm concerned that you've made a specific assumption of 2's compliment int.
>> Nothing in the spec or real world assures us of this. Intel x86 is 2's
>> compliment, but this is a bad assumption.
>
> I doubt we support 1s complement archs but if so, something like this
> would work:
>
> static const char xtoa_digits[] = "9876543210123456789";
> static const int xtoa_middle = (sizeof(xtoa_digits) - 1) / 2;
>
> APR_DECLARE(char *) apr_itoa(apr_pool_t *p, int n)
> {
> const int BUFFER_SIZE = sizeof(int) * 3 + 2;
> char *buf = apr_palloc(p, BUFFER_SIZE);
> char *start = buf + BUFFER_SIZE - 1;
> int negative = (n < 0);
> *start = 0;
> do {
> int tmp = n;
> n /= 10;
> *--start = xtoa_digits[xtoa_middle + tmp - n * 10];
> } while (n);
> if (negative) {
> *--start = '-';
> }
> return start;
> }
>
> Same for apr_ltoa() or apr_off_t_toa() (with the corresponding type
> for "tmp"), no sign assumption.
Re: svn commit: r1836519 - /apr/apr/trunk/strings/apr_strings.c
Posted by Yann Ylavic <yl...@gmail.com>.
On Tue, Jul 24, 2018 at 12:53 AM, William A Rowe Jr <wr...@rowe-clan.net> wrote:
> I'm concerned that you've made a specific assumption of 2's compliment int.
> Nothing in the spec or real world assures us of this. Intel x86 is 2's
> compliment, but this is a bad assumption.
I doubt we support 1s complement archs but if so, something like this
would work:
static const char xtoa_digits[] = "9876543210123456789";
static const int xtoa_middle = (sizeof(xtoa_digits) - 1) / 2;
APR_DECLARE(char *) apr_itoa(apr_pool_t *p, int n)
{
const int BUFFER_SIZE = sizeof(int) * 3 + 2;
char *buf = apr_palloc(p, BUFFER_SIZE);
char *start = buf + BUFFER_SIZE - 1;
int negative = (n < 0);
*start = 0;
do {
int tmp = n;
n /= 10;
*--start = xtoa_digits[xtoa_middle + tmp - n * 10];
} while (n);
if (negative) {
*--start = '-';
}
return start;
}
Same for apr_ltoa() or apr_off_t_toa() (with the corresponding type
for "tmp"), no sign assumption.
Re: svn commit: r1836519 - /apr/apr/trunk/strings/apr_strings.c
Posted by William A Rowe Jr <wr...@rowe-clan.net>.
I'm concerned that you've made a specific assumption of 2's compliment int.
Nothing in the spec or real world assures us of this. Intel x86 is 2's
compliment, but this is a bad assumption.
On Mon, Jul 23, 2018, 17:33 Yann Ylavic <yl...@gmail.com> wrote:
> On Tue, Jul 24, 2018 at 12:28 AM, <ni...@apache.org> wrote:
> >
> > @@ -387,18 +389,20 @@ APR_DECLARE(char *) apr_ltoa(apr_pool_t
> > char *buf = apr_palloc(p, BUFFER_SIZE);
> > char *start = buf + BUFFER_SIZE - 1;
> > int negative;
> > + unsigned int un;
>
> unsigned long for ltoa?
>
> > if (n < 0) {
> > negative = 1;
> > - n = -n;
> > + un = -n;
> > }
> > else {
> > negative = 0;
> > + un = n;
> > }
> > *start = 0;
> > do {
> > - *--start = (char)('0' + (n % 10));
> > - n /= 10;
> > - } while (n);
> > + *--start = (char)('0' + (un % 10));
> > + un /= 10;
> > + } while (un);
> > if (negative) {
> > *--start = '-';
> > }
>
> Regards,
> Yann.
>