diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 16d5d14..4d031e7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -49,7 +49,7 @@ jobs: glib: [ enable-glib, disable-glib ] steps: - name: Install packages - run: brew install bison gawk automake + run: brew install bison gawk automake glib - uses: actions/checkout@v2 - name: Fetch test data run: git clone https://github.com/mdbtools/mdbtestdata.git test @@ -89,7 +89,7 @@ jobs: - name: Remove packages run: brew unlink unixodbc - name: Install packages - run: brew install libiodbc bison gawk automake + run: brew install libiodbc bison gawk automake glib - uses: actions/checkout@v2 - name: Fetch test data run: git clone https://github.com/mdbtools/mdbtestdata.git test diff --git a/.gitignore b/.gitignore index d946b1d..715fee0 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ m4/ !m4/ccalias.m4 !m4/iconv.m4 !m4/readline.m4 +/test/ config.log config.status configure diff --git a/src/libmdb/data.c b/src/libmdb/data.c index 5b5668b..be59a75 100644 --- a/src/libmdb/data.c +++ b/src/libmdb/data.c @@ -894,9 +894,6 @@ mdb_date_to_tm(double td, struct tm *t) long yr, q; const int *cal; - if (td < 0.0 || td > 1e6) // About 2700 AD - return; - yr = 1; day = (long)(td); time = (long)((td - day) * 86400.0 + 0.5); @@ -940,12 +937,21 @@ static char * mdb_date_to_string(MdbHandle *mdb, const char *fmt, void *buf, int start) { struct tm t = { 0 }; - char *text = g_malloc(mdb->bind_size); + char *text = NULL; double td = mdb_get_double(buf, start); - mdb_date_to_tm(td, &t); - - strftime(text, mdb->bind_size, mdb->date_fmt, &t); + // limit dates to protect from overflow. + // 1e6 days is ~2700 years, centered at 1900, so this range is: + // Sunday, February 4, 839 BC to Tuesday, November 28, 4637 + if (td < -1e6 || td > 1e6) { + // an "invalid date" would perhaps be better than null (TODO) + // fprintf(stderr, "Warning: mdb_date_to_string called on unsupported date with %f days.\n", td); + text = g_strdup(""); + } else { + text = g_malloc(mdb->bind_size); + mdb_date_to_tm(td, &t); + strftime(text, mdb->bind_size, fmt, &t); + } return text; } @@ -1046,9 +1052,6 @@ char *mdb_col_to_string(MdbHandle *mdb, void *buf, int start, int datatype, int size, text, mdb->bind_size); } break; - case MDB_DATETIME: - text = mdb_date_to_string(mdb, mdb->date_fmt, buf, start); - break; case MDB_MEMO: text = mdb_memo_to_string(mdb, start, size); break; diff --git a/test_script.sh b/test_script.sh index 083fef9..ede5db2 100755 --- a/test_script.sh +++ b/test_script.sh @@ -16,3 +16,4 @@ ./src/util/mdb-ver test/data/ASampleDatabase.accdb ./src/util/mdb-ver test/data/nwind.mdb ./src/util/mdb-queries test/data/ASampleDatabase.accdb qryCostsSummedByOwner +./src/util/mdb-export -X '@' -d '|' -D %F -T '%F %T' -R "\n" -q '"' -H -e test/data/DateTestDatabase.mdb DateTest \ No newline at end of file