From f98a501c024d692c61eed9f72b06b5288ae24078 Mon Sep 17 00:00:00 2001 From: Matt Hill Date: Tue, 17 Mar 2015 00:22:02 -0400 Subject: [PATCH] Using explicity bit-length for longs to prevent overflow --- src/openalpr/alpr.h | 3 ++- src/openalpr/alpr_impl.cpp | 2 +- src/openalpr/support/filesystem.cpp | 10 +++++----- src/openalpr/support/filesystem.h | 4 ++-- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/openalpr/alpr.h b/src/openalpr/alpr.h index d06b408..1fd89de 100644 --- a/src/openalpr/alpr.h +++ b/src/openalpr/alpr.h @@ -23,6 +23,7 @@ #include #include #include +#include namespace alpr { @@ -94,7 +95,7 @@ namespace alpr AlprResults() {}; virtual ~AlprResults() {}; - long epoch_time; + int64_t epoch_time; int img_width; int img_height; float total_processing_time_ms; diff --git a/src/openalpr/alpr_impl.cpp b/src/openalpr/alpr_impl.cpp index 56c1b1c..6ca7bfa 100644 --- a/src/openalpr/alpr_impl.cpp +++ b/src/openalpr/alpr_impl.cpp @@ -426,7 +426,7 @@ namespace alpr cJSON* root = cJSON_Parse(json.c_str()); int version = cJSON_GetObjectItem(root, "version")->valueint; - allResults.epoch_time = (long) cJSON_GetObjectItem(root, "epoch_time")->valuedouble; + allResults.epoch_time = (int64_t) cJSON_GetObjectItem(root, "epoch_time")->valuedouble; allResults.img_width = cJSON_GetObjectItem(root, "img_width")->valueint; allResults.img_height = cJSON_GetObjectItem(root, "img_height")->valueint; allResults.total_processing_time_ms = cJSON_GetObjectItem(root, "processing_time_ms")->valueint; diff --git a/src/openalpr/support/filesystem.cpp b/src/openalpr/support/filesystem.cpp index 2bee99c..e8df8ac 100644 --- a/src/openalpr/support/filesystem.cpp +++ b/src/openalpr/support/filesystem.cpp @@ -119,14 +119,14 @@ namespace alpr #ifdef WINDOWS // Stub out these functions on Windows. They're used for the daemon anyway, which isn't supported on Windows. - long getFileSize(std::string filename) { return 0; } + int64_t getFileSize(std::string filename) { return 0; } static int makeDir(char *path, mode_t mode) { return 0; } bool makePath(char* path, mode_t mode) { return true; } - long getFileCreationTime(std::string filename) { return 0; } + int64_t getFileCreationTime(std::string filename) { return 0; } #else - long getFileSize(std::string filename) + int64_t getFileSize(std::string filename) { struct stat stat_buf; int rc = stat(filename.c_str(), &stat_buf); @@ -139,7 +139,7 @@ namespace alpr return -1; } - long getFileCreationTime(std::string filename) + int64_t getFileCreationTime(std::string filename) { struct stat stat_buf; int rc = stat(filename.c_str(), &stat_buf); @@ -153,7 +153,7 @@ namespace alpr double milliseconds = (stat_buf.st_ctim.tv_sec * 1000) + (((double) stat_buf.st_ctim.tv_nsec) / 1000000.0); #endif - return (long) milliseconds; + return (int64_t) milliseconds; } static int makeDir(const char *path, mode_t mode) diff --git a/src/openalpr/support/filesystem.h b/src/openalpr/support/filesystem.h index 9e146aa..b73d539 100644 --- a/src/openalpr/support/filesystem.h +++ b/src/openalpr/support/filesystem.h @@ -31,8 +31,8 @@ namespace alpr std::string filenameWithoutExtension(std::string filename); - long getFileSize(std::string filename); - long getFileCreationTime(std::string filename); + int64_t getFileSize(std::string filename); + int64_t getFileCreationTime(std::string filename); bool DirectoryExists( const char* pzPath ); bool fileExists( const char* pzPath );