summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Roche <xroche@users.noreply.github.com>2014-05-29 08:30:43 +0000
committerXavier Roche <xroche@users.noreply.github.com>2014-05-29 08:30:43 +0000
commit194ebad4c6f4d259d5b2fd7349246ea19493cb04 (patch)
tree49f49c1eb0b73580c86793cd7dfb6168ada583f6
parentae6d05fbb30ca8c0370b2be8cc1810b028616830 (diff)
Added off_t_to_size_t()
-rw-r--r--src/htscore.c14
-rw-r--r--src/htslib.h8
-rw-r--r--src/htsserver.c2
3 files changed, 16 insertions, 8 deletions
diff --git a/src/htscore.c b/src/htscore.c
index e754c39..31deb57 100644
--- a/src/htscore.c
+++ b/src/htscore.c
@@ -711,9 +711,9 @@ int httpmirror(char *url1, httrackp * opt) {
/* OPTIMIZED for fast load */
if (StringNotEmpty(opt->filelist)) {
char *filelist_buff = NULL;
- off_t filelist_sz = fsize(StringBuff(opt->filelist));
+ const size_t filelist_sz = off_t_to_size_t(fsize(StringBuff(opt->filelist)));
- if (filelist_sz > 0) {
+ if (filelist_sz != (size_t) -1) {
FILE *fp = fopen(StringBuff(opt->filelist), "rb");
if (fp) {
@@ -2149,16 +2149,16 @@ int httpmirror(char *url1, httrackp * opt) {
(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log),
"hts-cache/old.lst"), "rb");
if (old_lst) {
- off_t sz =
- fsize(fconcat
+ const size_t sz =
+ off_t_to_size_t(fsize(fconcat
(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log),
- "hts-cache/new.lst"));
+ "hts-cache/new.lst")));
new_lst =
fopen(fconcat
(OPT_GET_BUFF(opt), OPT_GET_BUFF_SIZE(opt), StringBuff(opt->path_log),
"hts-cache/new.lst"), "rb");
- if ((new_lst) && (sz > 0)) {
- char *adr = (char *) malloct(sz);
+ if (new_lst != NULL && sz != (size_t) -1) {
+ char *const adr = (char *) malloct(sz);
if (adr) {
if (fread(adr, 1, sz, new_lst) == sz) {
diff --git a/src/htslib.h b/src/htslib.h
index 30bd2f4..d56b379 100644
--- a/src/htslib.h
+++ b/src/htslib.h
@@ -612,6 +612,14 @@ HTS_STATIC int compare_mime(httrackp * opt, const char *mime, const char *file,
#endif
+// returns (size_t) -1 upon error
+static size_t off_t_to_size_t(off_t o) {
+ if (o >= 0 && o < ( (size_t) -1 ) / 2) {
+ } else {
+ return (size_t) -1;
+ }
+}
+
/* dirent() compatibility */
#ifdef _WIN32
#define HTS_DIRENT_SIZE 256
diff --git a/src/htsserver.c b/src/htsserver.c
index 2e840e1..401f131 100644
--- a/src/htsserver.c
+++ b/src/htsserver.c
@@ -1596,7 +1596,7 @@ static int htslang_load(char *limit_to, const char *path) {
/* Add key */
if (strnotempty(intkey)) {
const size_t len = strlen(value);
- char *const buff = (char *) malloc(len + 2);
+ char *const buff = (char *) malloc(len + 1);
if (buff) {
conv_printf(value, buff);
inthash_add(NewLangStr, intkey, (intptr_t) buff);