ben-strasser / fast-cpp-csv-parser

fast-cpp-csv-parser
BSD 3-Clause "New" or "Revised" License
2.11k stars 440 forks source link

Fix implicit conversion warnings for int/size_t #76

Closed ezillinger closed 3 years ago

ezillinger commented 5 years ago

This allows the project to build with warnings cranked all the way up. It fixes the following warnings:

fast-cpp-csv-parser\csv.h(156,1): error C2220: warning treated as error - no 'object' file generated
                                return std::fread(buffer, 1, size, file);
^
fast-cpp-csv-parser\csv.h(156,1): warning C4365: 'argument': conversion from 'int' to 'size_t', signed/unsigned mismatch
                                return std::fread(buffer, 1, size, file);
^
fast-cpp-csv-parser\csv.h(156,1): warning C4267: 'return': conversion from 'size_t' to 'int', possible loss of data
                                return std::fread(buffer, 1, size, file);
^
fast-cpp-csv-parser\csv.h(156,1): warning C4365: 'return': conversion from 'size_t' to 'int', signed/unsigned mismatch
                                return std::fread(buffer, 1, size, file);
^
fast-cpp-csv-parser\csv.h(190,1): warning C4365: 'argument': conversion from 'int' to 'size_t', signed/unsigned mismatch
                                std::memcpy(buffer, str, to_copy_byte_count);
^
fast-cpp-csv-parser\csv.h(466,1): warning C4365: 'argument': conversion from 'int' to 'size_t', signed/unsigned mismatch
                        while(buffer[line_end] != '\n' && line_end != data_end){
^
fast-cpp-csv-parser\csv.h(473,1): warning C4365: 'argument': conversion from 'unsigned int' to 'int', signed/unsigned mismatch
                                err.set_file_line(file_line);
^
fast-cpp-csv-parser\csv.h(477,1): warning C4365: 'argument': conversion from 'int' to 'size_t', signed/unsigned mismatch
                        if(buffer[line_end] == '\n' && line_end != data_end){
^
fast-cpp-csv-parser\csv.h(478,1): warning C4365: 'argument': conversion from 'int' to 'size_t', signed/unsigned mismatch
                                buffer[line_end] = '\0';
^
fast-cpp-csv-parser\csv.h(483,1): warning C4365: 'argument': conversion from 'int' to 'size_t', signed/unsigned mismatch
                                buffer[line_end] = '\0';
^
fast-cpp-csv-parser\csv.h(487,1): warning C4365: 'argument': conversion from 'int' to 'size_t', signed/unsigned mismatch
                        if(line_end != data_begin && buffer[line_end-1] == '\r')
^
fast-cpp-csv-parser\csv.h(488,1): warning C4365: 'argument': conversion from 'int' to 'size_t', signed/unsigned mismatch
                                buffer[line_end-1] = '\0';
ezillinger commented 5 years ago

I see that there are all kinds of additional warnings when you start using all of the templates. I'll try to make a pull request for those as I run into them. Do you have any unit tests (or code that uses all of the features) that I can test with?

SvenRoederer commented 3 years ago

we also started to create a fix for these conversion-warnings and realized this pending patch. What's holding back from merging?

ben-strasser commented 3 years ago

What's holding back from merging?

Adding static_cast everywhere decreases readability.

Warning about every single signed/unsigned conversion is not useful. I understand warning about comparisons as -1 == 0xFFFFFFFFu being true is quite surprising. However, warning about every conversion? Sorry, no. I refuse to maintain that.

This is also a pure MSVC problem. Both GCC and Clang compile without a warning with -Wall -Wextra.