libroot: return error on partial match in strptime()
The previously implemented behavior of strptime() allowed for partial matches of strings. For example, if the format string was "%a, %d %b %Y %H:%M:%S", it would successfully parse "Sun, 07 Dec 2003" as input. This is inconsistent with the standardization in POSIX.1-2001 (and later). This change makes strptime() return an error if there is no more data in the buffer and not the entire format string is parsed. Change-Id: If066c49fb7fc094f8ccd56703cd01903a0e40cb3 Reviewed-on: https://review.haiku-os.org/c/haiku/+/5298 Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org> Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>
This commit is contained in:
parent
7ff9722ae3
commit
929355add7
@ -55,9 +55,6 @@ _strptime(const char *buf, const char *fmt, struct tm *tm, int *GMTp)
|
||||
|
||||
ptr = fmt;
|
||||
while (*ptr != 0) {
|
||||
if (*buf == 0)
|
||||
break;
|
||||
|
||||
c = *ptr++;
|
||||
|
||||
if (c != '%') {
|
||||
@ -74,7 +71,6 @@ _strptime(const char *buf, const char *fmt, struct tm *tm, int *GMTp)
|
||||
label:
|
||||
c = *ptr++;
|
||||
switch (c) {
|
||||
case 0:
|
||||
case '%':
|
||||
if (*buf++ != '%')
|
||||
return 0;
|
||||
@ -479,6 +475,9 @@ label:
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return (char *)buf;
|
||||
|
Loading…
x
Reference in New Issue
Block a user