Using explicity bit-length for longs to prevent overflow

This commit is contained in:
Matt Hill
2015-03-17 00:22:02 -04:00
parent 8aded3b750
commit f98a501c02
4 changed files with 10 additions and 9 deletions

View File

@@ -23,6 +23,7 @@
#include <iostream>
#include <vector>
#include <fstream>
#include <inttypes.h>
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;

View File

@@ -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;

View File

@@ -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)

View File

@@ -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 );