Bug#998737: Problem found with possible fix suggestion
ADA
adanrg at gmail.com
Thu Dec 9 13:11:27 GMT 2021
Hi,
I've found the problem, why the timestamp, which should be in ISO 8601
format gets "corrupted". This problem exists in all current GNote
packages, including the original source (GitLab GNote master).
The problem is in datetime.cpp, function date_time_to_iso8601.
Link on GitLab:
https://gitlab.gnome.org/GNOME/gnote/-/blob/master/src/sharp/datetime.cpp
Bug was introduced with this commit:
https://gitlab.gnome.org/GNOME/gnote/-/commit/b30cd91826d2ee3b953b2485683ba8011be0434d
Short C program to demonstrate the problem, let's reuse portion of
that function and dump the current timestamp to the console:
#include <stdio.h>
#include <string.h>
int main(void) {
char buffer[36] = {0};
sprintf(buffer, "%d-%02d-%02dT%02d:%02d:%02.6lfZ", 2021, 12, 9, 13,
51, 3.01918745645);
printf("%s\n", buffer);
}
This outputs:
2021-12-09T13:51:3.019187Z
There's no zero padding in the seconds part, due to how %02.6 is
interpreted for floats. This is a possible fix:
#include <stdio.h>
#include <string.h>
int main(void) {
char buffer[36] = {0};
sprintf(buffer, "%d-%02d-%02dT%02d:%02d:%09.6lfZ", 2021, 12, 9, 13,
51, 3.01918745645);
printf("%s\n", buffer);
}
This outputs:
2021-12-09T13:51:03.019187Z
This is what we want to see. Just change %02.6lf to %09.6lf in the
sprintf call.
IMHO, this should be also communicated upstream. Thanks!
Best regards,
Zoltan Adasz
More information about the pkg-gnome-maintainers
mailing list