Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TzParser: fix parsing of ttisstd and ttisgmt #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions Src/TzParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,15 @@ TzTransitionList parseTimeZone(const char* tzName)
The number of characters of "time zone abbreviation strings" stored in the file.
*/

long ttisgmtCnt = 0;
long ttisstdCnt = 0;
long leapCnt = 0;
long timeCnt = 0;
long typeCnt = 0;
long charCnt = 0;

(void) ttisgmtCnt;
(void) ttisstdCnt;
(void) leapCnt;
(void) timeCnt;
(void) typeCnt;
Expand All @@ -207,14 +211,16 @@ TzTransitionList parseTimeZone(const char* tzName)

DBG("-----------------------------------------------------\n");

if (memcmp(buf, TZ_MAGIC, 4) != 0) {
if (memcmp(buf+index, TZ_MAGIC, 4) != 0) {
printf("Not a tz file. Header signature mismatch: %s\n", filePath.c_str());
free(buf);
return TzTransitionList();
}

struct tzhead* head = (struct tzhead*) (buf + index);

ttisgmtCnt = detzcode(head->tzh_ttisgmtcnt);
ttisstdCnt = detzcode(head->tzh_ttisstdcnt);
leapCnt = detzcode(head->tzh_leapcnt);
timeCnt = detzcode(head->tzh_timecnt);
typeCnt = detzcode(head->tzh_typecnt);
Expand Down Expand Up @@ -339,7 +345,7 @@ TzTransitionList parseTimeZone(const char* tzName)
time or wall clock time, and are used when a time zone file is
used in handling POSIX-style time zone environment variables.
*/
for (long i = 0; i < typeCnt; i++) {
for (long i = 0; i < ttisstdCnt; i++) {

int standardOrWallClock = (unsigned char) buf[index];
index++;
Expand All @@ -356,7 +362,7 @@ TzTransitionList parseTimeZone(const char* tzName)
specified as UTC or local time, and are used when a time zone
file is used in handling POSIX-style time zone environment variables.
*/
for (long i = 0; i < typeCnt; i++) {
for (long i = 0; i < ttisgmtCnt; i++) {

int utcOrLocalTime = (unsigned char) buf[index];
index++;
Expand Down