[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Bug-wget] [PATCH] Invalid Content-Length header in WARC files, on s
From: |
Tim Ruehsen |
Subject: |
Re: [Bug-wget] [PATCH] Invalid Content-Length header in WARC files, on some platforms |
Date: |
Tue, 27 Nov 2012 14:47:22 +0100 |
User-agent: |
KMail/1.13.7 (Linux/3.2.0-4-amd64; KDE/4.8.4; x86_64; ; ) |
Am Monday 26 November 2012 schrieb Ángel González:
> On 26/11/12 00:04, Giuseppe Scrivano wrote:
> > that is a good idea, we can add something like:
> >
> > #define MAX_INT_TO_STRING_LEN(x) (sizeof(x) * 24082 / 10000) + 2
> >
> > where `x' in our case will be off_t.
> >
> > I am not sure if such a function already exists somewhere.
> >
> > Does it improve readability?
>
> Well, that just brings the question «Where does 24082 come from?» but if
> that used for eg.
simply said (well, not simply - it had to refresh my knowledge ;-)
sizeof(x) = log256(max(x))
=> sizeof(x) = log10(max(x)) / log10(256)
=> sizeof(x) * log10(256) = log10(max(x)) [log10(max(x)) is what we need !]
=> sizeof(x) * log10(256) = log10(max(x))
=> sizeof(x) * 2,4082... = log10(max(x))
~= sizeof(x) * 24082 / 10000 = log10(max(x))
and for completeness: plus one for trailing \0 and plus one for the sign
But why so complicated ? 32 is a good value even for 64bit and aligns
succeeding memory to a 16 byte boundary.
If you want to save memory, you could calculate the needed size replacing
max(x) by your value and make a inline function out of MAX_INT_TO_STRING_LEN -
ok, but then you need the C99 feature 'variable length arrays' ;-)
MAX_INT_TO_STRING_LEN should be renamed to make clear that we are talking
about converting int to a DECIMAL string, e.g. MAX_INT_TO_DEC_LEN.
Regards, Tim
- Re: [Bug-wget] [PATCH] Invalid Content-Length header in WARC files, on some platforms, (continued)
- Re: [Bug-wget] [PATCH] Invalid Content-Length header in WARC files, on some platforms, Giuseppe Scrivano, 2012/11/24
- Re: [Bug-wget] [PATCH] Invalid Content-Length header in WARC files, on some platforms, Ángel González, 2012/11/24
- Re: [Bug-wget] [PATCH] Invalid Content-Length header in WARC files, on some platforms, Stephanie Rühsen, 2012/11/24
- Re: [Bug-wget] [PATCH] Invalid Content-Length header in WARC files, on some platforms, Ángel González, 2012/11/24
- Re: [Bug-wget] [PATCH] Invalid Content-Length header in WARC files, on some platforms, Giuseppe Scrivano, 2012/11/25
- Re: [Bug-wget] [PATCH] Invalid Content-Length header in WARC files, on some platforms, Tim Ruehsen, 2012/11/26
- Re: [Bug-wget] [PATCH] Invalid Content-Length header in WARC files, on some platforms, Ángel González, 2012/11/26
- Re: [Bug-wget] [PATCH] Invalid Content-Length header in WARC files, on some platforms, Giuseppe Scrivano, 2012/11/25
- Re: [Bug-wget] [PATCH] Invalid Content-Length header in WARC files, on some platforms, Ángel González, 2012/11/26
- Re: [Bug-wget] [PATCH] Invalid Content-Length header in WARC files, on some platforms, Giuseppe Scrivano, 2012/11/26
- Re: [Bug-wget] [PATCH] Invalid Content-Length header in WARC files, on some platforms,
Tim Ruehsen <=
Re: [Bug-wget] Invalid Content-Length header in WARC files, on some platforms, David Ryskalczyk, 2012/11/13