mirror of
https://github.com/fluencelabs/musl
synced 2025-06-30 15:11:55 +00:00
fix unhandled cases in strptime
%C, %U, %W, and %y handling were completely missing; %C wrongly fell-through to unrelated cases, and the rest returned failure. for now, they all parse numbers in the proper forms and range-check the values, but they do not store the value anywhere. it's not clear to me whether, as "derived" fields, %U and %W should produce any result. they certainly cannot produce a result unless the year and weekday are also converted, but in this case it might be desirable for them to do so. clarification is needed on the intended behavior of strptime in cases like this. %C and %y have well-defined behavior as long as they are used together (and %y is defined by itself but may change in the future). implementing them (including their correct interaction) is left as a later change to be made. finally, strptime now rejects unknown/invalid format characters instead of ignoring them.
This commit is contained in:
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
char *strptime(const char *restrict s, const char *restrict f, struct tm *restrict tm)
|
char *strptime(const char *restrict s, const char *restrict f, struct tm *restrict tm)
|
||||||
{
|
{
|
||||||
int i, w, neg, adj, min, range, *dest;
|
int i, w, neg, adj, min, range, *dest, dummy;
|
||||||
const char *ex;
|
const char *ex;
|
||||||
size_t len;
|
size_t len;
|
||||||
while (*f) {
|
while (*f) {
|
||||||
@ -40,6 +40,10 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri
|
|||||||
if (!s) return 0;
|
if (!s) return 0;
|
||||||
break;
|
break;
|
||||||
case 'C':
|
case 'C':
|
||||||
|
/* FIXME */
|
||||||
|
dest = &dummy;
|
||||||
|
if (w<0) w=2;
|
||||||
|
goto numeric_digits;
|
||||||
case 'd': case 'e':
|
case 'd': case 'e':
|
||||||
dest = &tm->tm_mday;
|
dest = &tm->tm_mday;
|
||||||
min = 1;
|
min = 1;
|
||||||
@ -112,8 +116,11 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri
|
|||||||
break;
|
break;
|
||||||
case 'U':
|
case 'U':
|
||||||
case 'W':
|
case 'W':
|
||||||
//FIXME
|
/* Throw away result, for now. (FIXME?) */
|
||||||
return 0;
|
dest = &dummy;
|
||||||
|
min = 0;
|
||||||
|
range = 54;
|
||||||
|
goto numeric_range;
|
||||||
case 'w':
|
case 'w':
|
||||||
dest = &tm->tm_wday;
|
dest = &tm->tm_wday;
|
||||||
min = 0;
|
min = 0;
|
||||||
@ -128,8 +135,10 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri
|
|||||||
if (!s) return 0;
|
if (!s) return 0;
|
||||||
break;
|
break;
|
||||||
case 'y':
|
case 'y':
|
||||||
//FIXME
|
/* FIXME */
|
||||||
return 0;
|
dest = &dummy;
|
||||||
|
w = 2;
|
||||||
|
goto numeric_digits;
|
||||||
case 'Y':
|
case 'Y':
|
||||||
dest = &tm->tm_year;
|
dest = &tm->tm_year;
|
||||||
if (w<0) w=4;
|
if (w<0) w=4;
|
||||||
@ -138,6 +147,8 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri
|
|||||||
case '%':
|
case '%':
|
||||||
if (*s++ != '%') return 0;
|
if (*s++ != '%') return 0;
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
numeric_range:
|
numeric_range:
|
||||||
if (!isdigit(*s)) return 0;
|
if (!isdigit(*s)) return 0;
|
||||||
*dest = 0;
|
*dest = 0;
|
||||||
|
Reference in New Issue
Block a user