--- parser3/src/main/pa_common.C 2020/11/21 23:26:26 1.317 +++ parser3/src/main/pa_common.C 2020/12/15 17:10:35 1.322 @@ -1,7 +1,7 @@ /** @file Parser: commonly functions. - Copyright (c) 2000-2017 Art. Lebedev Studio (http://www.artlebedev.com) + Copyright (c) 2000-2020 Art. Lebedev Studio (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) */ @@ -29,7 +29,7 @@ #define pa_mkdir(path, mode) mkdir(path, mode) #endif -volatile const char * IDENT_PA_COMMON_C="$Id: pa_common.C,v 1.317 2020/11/21 23:26:26 moko Exp $" IDENT_PA_COMMON_H IDENT_PA_HASH_H IDENT_PA_ARRAY_H IDENT_PA_STACK_H; +volatile const char * IDENT_PA_COMMON_C="$Id: pa_common.C,v 1.322 2020/12/15 17:10:35 moko Exp $" IDENT_PA_COMMON_H IDENT_PA_HASH_H IDENT_PA_ARRAY_H IDENT_PA_STACK_H; // some maybe-undefined constants @@ -110,18 +110,16 @@ int pa_get_valid_file_options_count(Hash #ifndef DOXYGEN struct File_read_action_info { char **data; size_t *data_size; - char* buf; size_t offset; size_t limit; + char* buf; uint64_t offset; size_t limit; }; #endif static void file_read_action(struct stat& finfo, int f, const String& file_spec, void *context) { File_read_action_info& info = *static_cast(context); - size_t to_read_size = info.limit; - if(!to_read_size) - to_read_size = check_file_size(finfo.st_size, &file_spec); + size_t to_read_size = check_file_size(info.limit && info.limit < finfo.st_size ? info.limit : finfo.st_size, &file_spec); if(to_read_size) { if(info.offset) - lseek(f, info.offset, SEEK_SET); + pa_lseek(f, info.offset, SEEK_SET); // seek never fails as POSIX allows the file offset to be set beyond the EOF *info.data = info.buf ? info.buf : (char *)pa_malloc_atomic(to_read_size+1); ssize_t result = read(f, *info.data, to_read_size); if(result<0) @@ -136,7 +134,7 @@ static void file_read_action(struct stat } } -File_read_result file_read_binary(const String& file_spec, bool fail_on_read_problem, char* buf, size_t offset, size_t limit) { +File_read_result file_read_binary(const String& file_spec, bool fail_on_read_problem, char* buf, uint64_t offset, size_t limit) { File_read_result result = {false, 0, 0, 0}; File_read_action_info info = {&result.str, &result.length, buf, offset, limit}; @@ -532,7 +530,7 @@ bool file_stat(const String& file_spec, } size_t check_file_size(uint64_t size, const String* file_spec){ - if(size > pa_file_size_limit) + if(size > (uint64_t)pa_file_size_limit) throw Exception(PARSER_RUNTIME, file_spec, "content size of %.15g bytes exceeds the limit (%.15g bytes)", (double)size, (double)pa_file_size_limit); return (size_t)size; } @@ -945,8 +943,8 @@ const char* hex_string(unsigned char* by return bytes_hex; } -int file_block_read(const int f, unsigned char* buffer, const size_t size){ - int nCount = read(f, buffer, size); +ssize_t file_block_read(const int f, void* buffer, const size_t size){ + ssize_t nCount = read(f, buffer, size); if (nCount < 0) throw Exception("file.read", 0, "read failed: %s (%d)", strerror(errno), errno); return nCount;