From 2d26b31ed306b9b47a2829b4a0fb1bfffaa9311b Mon Sep 17 00:00:00 2001 From: Thomas Kittelmann Date: Sun, 4 Sep 2016 20:31:20 +0200 Subject: [PATCH] import from dgcode mercurial: version 0.99.1 --- VERSION | 2 +- src/mcpl/mcpl.c | 13 ++++++++----- src/mcpl/mcpl.h | 4 ++-- src_fat/mcpl2ssw_app_fat.c | 17 ++++++++++------- src_fat/mcpl_fat.c | 13 ++++++++----- src_fat/mcpltool_app_fat.c | 17 ++++++++++------- src_fat/ssw2mcpl_app_fat.c | 17 ++++++++++------- 7 files changed, 49 insertions(+), 34 deletions(-) diff --git a/VERSION b/VERSION index 0178172..626c498 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.99.0 +0.99.1 diff --git a/src/mcpl/mcpl.c b/src/mcpl/mcpl.c index e01daa7..d819ca0 100644 --- a/src/mcpl/mcpl.c +++ b/src/mcpl/mcpl.c @@ -1549,7 +1549,8 @@ int mcpl_tool_usage( char** argv, const char * errmsg ) { int mcpl_str2int(const char* str, size_t len, int64_t* res) { - //portable 64bit str2int with error checking. + //portable 64bit str2int with error checking (only INT64_MIN might not be + //possible to specify). *res = 0; if (!len) len=strlen(str); @@ -1566,11 +1567,12 @@ int mcpl_str2int(const char* str, size_t len, int64_t* res) if (str[i]<'0'||str[i]>'9') { return 0; } + int64_t prev = tmp; tmp *= 10; tmp += str[i] - '0'; + if (prev>=tmp) + return 1;//overflow (hopefully it did not trigger a signal or FPE) } - if (tmp > INT64_MAX) - return 0; *res = sign * tmp; return 1; } @@ -1721,7 +1723,7 @@ int mcpl_tool(int argc,char** argv) { int32_t pdgcode_select = 0; if (pdgcode_str) { int64_t pdgcode64; - if (!mcpl_str2int(pdgcode_str, 0, &pdgcode64) || pdgcode64INT32_MAX || !pdgcode64) + if (!mcpl_str2int(pdgcode_str, 0, &pdgcode64) || pdgcode64<-2147483648 || pdgcode64>2147483647 || !pdgcode64) return mcpl_tool_usage(argv,"Must specify non-zero 32bit integer as argument to -p."); pdgcode_select = (int32_t)pdgcode64; } @@ -1729,7 +1731,8 @@ int mcpl_tool(int argc,char** argv) { if (opt_num_skip>0) mcpl_seek(fi,(uint64_t)opt_num_skip); - uint64_t left = opt_num_limit>0 ? (uint64_t)opt_num_limit : UINT64_MAX; + //uint64_t(-1) instead of UINT64_MAX to fix clang c++98 compilation + uint64_t left = opt_num_limit>0 ? (uint64_t)opt_num_limit : (uint64_t)-1; uint64_t added = 0; const mcpl_particle_t* particle; while ( left-- && ( particle = mcpl_read(fi) ) ) { diff --git a/src/mcpl/mcpl.h b/src/mcpl/mcpl.h index 1621c79..8c61cd8 100644 --- a/src/mcpl/mcpl.h +++ b/src/mcpl/mcpl.h @@ -21,8 +21,8 @@ #define MCPL_VERSION_MAJOR 0 #define MCPL_VERSION_MINOR 99 -#define MCPL_VERSION_PATCH 0 -#define MCPL_VERSION 9900 /* (10000*MAJOR+100*MINOR+PATCH) */ +#define MCPL_VERSION_PATCH 1 +#define MCPL_VERSION 9901 /* (10000*MAJOR+100*MINOR+PATCH) */ #define MCPL_FORMATVERSION 2 /* Format version of written files */ #ifdef __cplusplus diff --git a/src_fat/mcpl2ssw_app_fat.c b/src_fat/mcpl2ssw_app_fat.c index 6948af4..9a22aec 100644 --- a/src_fat/mcpl2ssw_app_fat.c +++ b/src_fat/mcpl2ssw_app_fat.c @@ -70,8 +70,8 @@ #define MCPL_VERSION_MAJOR 0 #define MCPL_VERSION_MINOR 99 -#define MCPL_VERSION_PATCH 0 -#define MCPL_VERSION 9900 /* (10000*MAJOR+100*MINOR+PATCH) */ +#define MCPL_VERSION_PATCH 1 +#define MCPL_VERSION 9901 /* (10000*MAJOR+100*MINOR+PATCH) */ #define MCPL_FORMATVERSION 2 /* Format version of written files */ #ifdef __cplusplus @@ -4193,7 +4193,8 @@ int mcpl_tool_usage( char** argv, const char * errmsg ) { int mcpl_str2int(const char* str, size_t len, int64_t* res) { - //portable 64bit str2int with error checking. + //portable 64bit str2int with error checking (only INT64_MIN might not be + //possible to specify). *res = 0; if (!len) len=strlen(str); @@ -4210,11 +4211,12 @@ int mcpl_str2int(const char* str, size_t len, int64_t* res) if (str[i]<'0'||str[i]>'9') { return 0; } + int64_t prev = tmp; tmp *= 10; tmp += str[i] - '0'; + if (prev>=tmp) + return 1;//overflow (hopefully it did not trigger a signal or FPE) } - if (tmp > INT64_MAX) - return 0; *res = sign * tmp; return 1; } @@ -4365,7 +4367,7 @@ int mcpl_tool(int argc,char** argv) { int32_t pdgcode_select = 0; if (pdgcode_str) { int64_t pdgcode64; - if (!mcpl_str2int(pdgcode_str, 0, &pdgcode64) || pdgcode64INT32_MAX || !pdgcode64) + if (!mcpl_str2int(pdgcode_str, 0, &pdgcode64) || pdgcode64<-2147483648 || pdgcode64>2147483647 || !pdgcode64) return mcpl_tool_usage(argv,"Must specify non-zero 32bit integer as argument to -p."); pdgcode_select = (int32_t)pdgcode64; } @@ -4373,7 +4375,8 @@ int mcpl_tool(int argc,char** argv) { if (opt_num_skip>0) mcpl_seek(fi,(uint64_t)opt_num_skip); - uint64_t left = opt_num_limit>0 ? (uint64_t)opt_num_limit : UINT64_MAX; + //uint64_t(-1) instead of UINT64_MAX to fix clang c++98 compilation + uint64_t left = opt_num_limit>0 ? (uint64_t)opt_num_limit : (uint64_t)-1; uint64_t added = 0; const mcpl_particle_t* particle; while ( left-- && ( particle = mcpl_read(fi) ) ) { diff --git a/src_fat/mcpl_fat.c b/src_fat/mcpl_fat.c index 3d29a1e..7092caf 100644 --- a/src_fat/mcpl_fat.c +++ b/src_fat/mcpl_fat.c @@ -3916,7 +3916,8 @@ int mcpl_tool_usage( char** argv, const char * errmsg ) { int mcpl_str2int(const char* str, size_t len, int64_t* res) { - //portable 64bit str2int with error checking. + //portable 64bit str2int with error checking (only INT64_MIN might not be + //possible to specify). *res = 0; if (!len) len=strlen(str); @@ -3933,11 +3934,12 @@ int mcpl_str2int(const char* str, size_t len, int64_t* res) if (str[i]<'0'||str[i]>'9') { return 0; } + int64_t prev = tmp; tmp *= 10; tmp += str[i] - '0'; + if (prev>=tmp) + return 1;//overflow (hopefully it did not trigger a signal or FPE) } - if (tmp > INT64_MAX) - return 0; *res = sign * tmp; return 1; } @@ -4088,7 +4090,7 @@ int mcpl_tool(int argc,char** argv) { int32_t pdgcode_select = 0; if (pdgcode_str) { int64_t pdgcode64; - if (!mcpl_str2int(pdgcode_str, 0, &pdgcode64) || pdgcode64INT32_MAX || !pdgcode64) + if (!mcpl_str2int(pdgcode_str, 0, &pdgcode64) || pdgcode64<-2147483648 || pdgcode64>2147483647 || !pdgcode64) return mcpl_tool_usage(argv,"Must specify non-zero 32bit integer as argument to -p."); pdgcode_select = (int32_t)pdgcode64; } @@ -4096,7 +4098,8 @@ int mcpl_tool(int argc,char** argv) { if (opt_num_skip>0) mcpl_seek(fi,(uint64_t)opt_num_skip); - uint64_t left = opt_num_limit>0 ? (uint64_t)opt_num_limit : UINT64_MAX; + //uint64_t(-1) instead of UINT64_MAX to fix clang c++98 compilation + uint64_t left = opt_num_limit>0 ? (uint64_t)opt_num_limit : (uint64_t)-1; uint64_t added = 0; const mcpl_particle_t* particle; while ( left-- && ( particle = mcpl_read(fi) ) ) { diff --git a/src_fat/mcpltool_app_fat.c b/src_fat/mcpltool_app_fat.c index 59c43a6..8ed1477 100644 --- a/src_fat/mcpltool_app_fat.c +++ b/src_fat/mcpltool_app_fat.c @@ -178,8 +178,8 @@ #define MCPL_VERSION_MAJOR 0 #define MCPL_VERSION_MINOR 99 -#define MCPL_VERSION_PATCH 0 -#define MCPL_VERSION 9900 /* (10000*MAJOR+100*MINOR+PATCH) */ +#define MCPL_VERSION_PATCH 1 +#define MCPL_VERSION 9901 /* (10000*MAJOR+100*MINOR+PATCH) */ #define MCPL_FORMATVERSION 2 /* Format version of written files */ #ifdef __cplusplus @@ -4119,7 +4119,8 @@ int mcpl_tool_usage( char** argv, const char * errmsg ) { int mcpl_str2int(const char* str, size_t len, int64_t* res) { - //portable 64bit str2int with error checking. + //portable 64bit str2int with error checking (only INT64_MIN might not be + //possible to specify). *res = 0; if (!len) len=strlen(str); @@ -4136,11 +4137,12 @@ int mcpl_str2int(const char* str, size_t len, int64_t* res) if (str[i]<'0'||str[i]>'9') { return 0; } + int64_t prev = tmp; tmp *= 10; tmp += str[i] - '0'; + if (prev>=tmp) + return 1;//overflow (hopefully it did not trigger a signal or FPE) } - if (tmp > INT64_MAX) - return 0; *res = sign * tmp; return 1; } @@ -4291,7 +4293,7 @@ int mcpl_tool(int argc,char** argv) { int32_t pdgcode_select = 0; if (pdgcode_str) { int64_t pdgcode64; - if (!mcpl_str2int(pdgcode_str, 0, &pdgcode64) || pdgcode64INT32_MAX || !pdgcode64) + if (!mcpl_str2int(pdgcode_str, 0, &pdgcode64) || pdgcode64<-2147483648 || pdgcode64>2147483647 || !pdgcode64) return mcpl_tool_usage(argv,"Must specify non-zero 32bit integer as argument to -p."); pdgcode_select = (int32_t)pdgcode64; } @@ -4299,7 +4301,8 @@ int mcpl_tool(int argc,char** argv) { if (opt_num_skip>0) mcpl_seek(fi,(uint64_t)opt_num_skip); - uint64_t left = opt_num_limit>0 ? (uint64_t)opt_num_limit : UINT64_MAX; + //uint64_t(-1) instead of UINT64_MAX to fix clang c++98 compilation + uint64_t left = opt_num_limit>0 ? (uint64_t)opt_num_limit : (uint64_t)-1; uint64_t added = 0; const mcpl_particle_t* particle; while ( left-- && ( particle = mcpl_read(fi) ) ) { diff --git a/src_fat/ssw2mcpl_app_fat.c b/src_fat/ssw2mcpl_app_fat.c index 18e9b7d..55d8a7d 100644 --- a/src_fat/ssw2mcpl_app_fat.c +++ b/src_fat/ssw2mcpl_app_fat.c @@ -70,8 +70,8 @@ #define MCPL_VERSION_MAJOR 0 #define MCPL_VERSION_MINOR 99 -#define MCPL_VERSION_PATCH 0 -#define MCPL_VERSION 9900 /* (10000*MAJOR+100*MINOR+PATCH) */ +#define MCPL_VERSION_PATCH 1 +#define MCPL_VERSION 9901 /* (10000*MAJOR+100*MINOR+PATCH) */ #define MCPL_FORMATVERSION 2 /* Format version of written files */ #ifdef __cplusplus @@ -4193,7 +4193,8 @@ int mcpl_tool_usage( char** argv, const char * errmsg ) { int mcpl_str2int(const char* str, size_t len, int64_t* res) { - //portable 64bit str2int with error checking. + //portable 64bit str2int with error checking (only INT64_MIN might not be + //possible to specify). *res = 0; if (!len) len=strlen(str); @@ -4210,11 +4211,12 @@ int mcpl_str2int(const char* str, size_t len, int64_t* res) if (str[i]<'0'||str[i]>'9') { return 0; } + int64_t prev = tmp; tmp *= 10; tmp += str[i] - '0'; + if (prev>=tmp) + return 1;//overflow (hopefully it did not trigger a signal or FPE) } - if (tmp > INT64_MAX) - return 0; *res = sign * tmp; return 1; } @@ -4365,7 +4367,7 @@ int mcpl_tool(int argc,char** argv) { int32_t pdgcode_select = 0; if (pdgcode_str) { int64_t pdgcode64; - if (!mcpl_str2int(pdgcode_str, 0, &pdgcode64) || pdgcode64INT32_MAX || !pdgcode64) + if (!mcpl_str2int(pdgcode_str, 0, &pdgcode64) || pdgcode64<-2147483648 || pdgcode64>2147483647 || !pdgcode64) return mcpl_tool_usage(argv,"Must specify non-zero 32bit integer as argument to -p."); pdgcode_select = (int32_t)pdgcode64; } @@ -4373,7 +4375,8 @@ int mcpl_tool(int argc,char** argv) { if (opt_num_skip>0) mcpl_seek(fi,(uint64_t)opt_num_skip); - uint64_t left = opt_num_limit>0 ? (uint64_t)opt_num_limit : UINT64_MAX; + //uint64_t(-1) instead of UINT64_MAX to fix clang c++98 compilation + uint64_t left = opt_num_limit>0 ? (uint64_t)opt_num_limit : (uint64_t)-1; uint64_t added = 0; const mcpl_particle_t* particle; while ( left-- && ( particle = mcpl_read(fi) ) ) {