Skip to contentSkip to conversation

tests: cal/bigyear only works on 64bit (sizeof(long) == 8) systems

DISCUSSION Mike Frysinger 3 participants 6 messages Dec 23, 2013 – Jan 13, 2014 Util-Linux package

lore
Share & tools
lore
#0 lore raw

the cal bigyear test uses a year of 1234567890123456789, but the parsing logic reads it in like so:

	year = strtol_or_err(*argv++, _("illegal year value"));

that's a signed long type, so on 32bit systems, you get:

          cal: Year 1234567890123456789       ...cal: illegal year value: 

'1234567890123456789': Numerical result out of range
cal: illegal year value: '1234567890123456789': Numerical result out of range
cal: illegal year value: '1234567890123456789': Numerical result out of range
cal: illegal year value: '1234567890123456789': Numerical result out of range
cal: illegal year value: '1234567890123456789': Numerical result out of range
cal: illegal year value: '1234567890123456789': Numerical result out of range
cal: illegal year value: '1234567890123456789': Numerical result out of range
cal: illegal year value: '1234567890123456789': Numerical result out of range
cal: illegal year value: '1234567890123456789': Numerical result out of range
cal: illegal year value: '1234567890123456789': Numerical result out of range
cal: illegal year value: '1234567890123456789': Numerical result out of range
FAILED (cal/bigyear)

should the test detect the sizeof(long) and then calculate a number that is smaller than that ?
-mike

maintainer
#1 lore raw
Quoted 19 lines · Mike Frysinger

the cal bigyear test uses a year of 1234567890123456789, but the parsing logic reads it in like so:

	year = strtol_or_err(*argv++, _("illegal year value"));

that's a signed long type, so on 32bit systems, you get:

          cal: Year 1234567890123456789       ...cal: illegal year value: 

'1234567890123456789': Numerical result out of range
cal: illegal year value: '1234567890123456789': Numerical result out of range
cal: illegal year value: '1234567890123456789': Numerical result out of range
cal: illegal year value: '1234567890123456789': Numerical result out of range
cal: illegal year value: '1234567890123456789': Numerical result out of range
cal: illegal year value: '1234567890123456789': Numerical result out of range
cal: illegal year value: '1234567890123456789': Numerical result out of range
cal: illegal year value: '1234567890123456789': Numerical result out of range
cal: illegal year value: '1234567890123456789': Numerical result out of range
cal: illegal year value: '1234567890123456789': Numerical result out of range
cal: illegal year value: '1234567890123456789': Numerical result out of range
FAILED (cal/bigyear)

Quoted 2 lines

should the test detect the sizeof(long) and then calculate a number that is smaller than that ?

It would be better to keep cal(1) arch insensitive.

Sami, why we need so huge year numbers and why the number is signed? I guess it would be enough to use "unsigned int" (UINT_MAX is 4294967295).

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#2 lore raw
Quoted 11 lines · Karel Zak
Quoted 5 lines · Mike Frysinger

that's a signed long type, so on 32bit systems, you get:

          cal: Year 1234567890123456789       ...cal: illegal year value:

should the test detect the sizeof(long) and then calculate a number that is smaller than that ?

It would be better to keep cal(1) arch insensitive.

Sami, why we need so huge year numbers and why the number is signed? I guess it would be enough to use "unsigned int" (UINT_MAX is 4294967295).

Hi Mike & Karel,

Year was left signed because someone said it might be interesting to know pre-year-zero outputs. After a bit research the pre-zero year calendars are theoretical construct, mostly because agreement in western world is not more than couple hundred years old. That means pre-zero calendar could only be considered as a what a modern western people think the calendar should have looked. Whether that is valuable, interesting, useful, etc is a different question.

Meanwhile the big year test is clearly broken. I recon there should be a version for various sizes of INT_MAX tests, and depending how large values are supported by system corresponding tests are ran.

Signature · 2 lines
Sami Kerola
http://www.iki.fi/kerolasa/
maintainer
#3 lore raw
Quoted 10 lines · Sami Kerola
Quoted 9 lines · Karel Zak
Quoted 5 lines · Mike Frysinger

that's a signed long type, so on 32bit systems, you get:

          cal: Year 1234567890123456789       ...cal: illegal year value:

should the test detect the sizeof(long) and then calculate a number that is smaller than that ?

It would be better to keep cal(1) arch insensitive.

Quoted 8 lines
Quoted 2 lines

Sami, why we need so huge year numbers and why the number is signed? I guess it would be enough to use "unsigned int" (UINT_MAX is 4294967295).

Hi Mike & Karel,

Year was left signed because someone said it might be interesting to know pre-year-zero outputs. After a bit research the pre-zero year calendars are theoretical construct, mostly because agreement in

but the code is:

    #define SMALLEST_YEAR           1

    if (ctl.req.year < SMALLEST_YEAR)
          errx(EXIT_FAILURE,  _("illegal year value: use positive integer"));
Quoted 8 lines

western world is not more than couple hundred years old. That means pre-zero calendar could only be considered as a what a modern western people think the calendar should have looked. Whether that is valuable, interesting, useful, etc is a different question.

Meanwhile the big year test is clearly broken. I recon there should be a version for various sizes of INT_MAX tests, and depending how large values are supported by system corresponding tests are ran.

INT_MAX is the same everywhere, all you need is to remove arch specific "long" from the code and use strtos32_or_err() to parse the year number.

(Well, I guess that 2147483647 years is enough :-)

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#4 lore raw
Quoted 11 lines · Karel Zak
Quoted 3 lines · Sami Kerola

Year was left signed because someone said it might be interesting to know pre-year-zero outputs. After a bit research the pre-zero year calendars are theoretical construct, mostly because agreement in

but the code is:

    #define SMALLEST_YEAR           1

    if (ctl.req.year < SMALLEST_YEAR)
          errx(EXIT_FAILURE,  _("illegal year value: use positive integer"));

Hi Karel,

That is correct right now. If negative years are allowed to be used I'm sure bug reports will follow. The leap year printouts are obviously wrong.

Quoted 9 lines
Quoted 3 lines

Meanwhile the big year test is clearly broken. I recon there should be a version for various sizes of INT_MAX tests, and depending how large values are supported by system corresponding tests are ran.

INT_MAX is the same everywhere, all you need is to remove arch specific "long" from the code and use strtos32_or_err() to parse the year number.

(Well, I guess that 2147483647 years is enough :-)

Use of 32 bit int is indeed the easiest fix, and I'm all in favor of cutting the cal output there.

Signature · 2 lines
Sami Kerola
http://www.iki.fi/kerolasa/
maintainer
#5 lore raw
Quoted 23 lines · Sami Kerola
Quoted 11 lines · Karel Zak
Quoted 3 lines · Sami Kerola

Year was left signed because someone said it might be interesting to know pre-year-zero outputs. After a bit research the pre-zero year calendars are theoretical construct, mostly because agreement in

but the code is:

    #define SMALLEST_YEAR           1

    if (ctl.req.year < SMALLEST_YEAR)
          errx(EXIT_FAILURE,  _("illegal year value: use positive integer"));

Hi Karel,

That is correct right now. If negative years are allowed to be used I'm sure bug reports will follow. The leap year printouts are obviously wrong.

Quoted 4 lines
Quoted 3 lines

Meanwhile the big year test is clearly broken. I recon there should be a version for various sizes of INT_MAX tests, and depending how large values are supported by system corresponding tests are ran.

Quoted 8 lines
Quoted 5 lines

INT_MAX is the same everywhere, all you need is to remove arch specific "long" from the code and use strtos32_or_err() to parse the year number.

(Well, I guess that 2147483647 years is enough :-)

Use of 32 bit int is indeed the easiest fix, and I'm all in favor of cutting the cal output there.

OK, I'm going to wait for the patch :-)

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com