mirror of
https://github.com/red0124/ssp.git
synced 2025-06-08 13:12:32 +02:00
Compare commits
No commits in common. "0ebbee1174be4e07c10012c76cff2fb33f10af63" and "110ee840ccd1ac53e2caabcd17b905c92a93c634" have entirely different histories.
0ebbee1174
...
110ee840cc
@ -28,15 +28,6 @@ inline void assert_throw_on_error_not_defined() {
|
||||
"'throw_on_error' is enabled");
|
||||
}
|
||||
|
||||
inline void* strict_realloc(void* ptr, size_t size) {
|
||||
ptr = realloc(ptr, size);
|
||||
if (!ptr) {
|
||||
throw std::bad_alloc{};
|
||||
}
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
#if __unix__
|
||||
inline ssize_t get_line_file(char** lineptr, size_t* n, FILE* stream) {
|
||||
return getline(lineptr, n, stream);
|
||||
@ -55,7 +46,13 @@ ssize_t get_line_file(char** lineptr, size_t* n, FILE* fp) {
|
||||
|
||||
if (*lineptr == nullptr || *n < sizeof(buff)) {
|
||||
size_t new_n = sizeof(buff);
|
||||
*lineptr = static_cast<char*>(strict_realloc(*lineptr, new_n));
|
||||
auto new_lineptr = static_cast<char*>(realloc(*lineptr, new_n));
|
||||
if (new_lineptr == nullptr) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
*lineptr = new_lineptr;
|
||||
*n = new_n;
|
||||
}
|
||||
|
||||
@ -69,7 +66,13 @@ ssize_t get_line_file(char** lineptr, size_t* n, FILE* fp) {
|
||||
if (*n <= buff_used + line_used) {
|
||||
size_t new_n = *n * 2;
|
||||
|
||||
*lineptr = static_cast<char*>(strict_realloc(*lineptr, new_n));
|
||||
auto new_lineptr = static_cast<char*>(realloc(*lineptr, new_n));
|
||||
if (new_lineptr == nullptr) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
*lineptr = new_lineptr;
|
||||
*n = new_n;
|
||||
}
|
||||
|
||||
|
@ -752,13 +752,22 @@ private:
|
||||
ssize_t get_line_buffer(char** lineptr, size_t* n,
|
||||
const char* const csv_data_buffer,
|
||||
size_t csv_data_size, size_t& curr_char) {
|
||||
if (lineptr == nullptr || n == nullptr ||
|
||||
csv_data_buffer == nullptr) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (curr_char >= csv_data_size) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (*lineptr == nullptr || *n < get_line_initial_buffer_size) {
|
||||
auto new_lineptr = static_cast<char*>(
|
||||
strict_realloc(*lineptr, get_line_initial_buffer_size));
|
||||
realloc(*lineptr, get_line_initial_buffer_size));
|
||||
if (new_lineptr == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
*lineptr = new_lineptr;
|
||||
*n = get_line_initial_buffer_size;
|
||||
}
|
||||
@ -769,7 +778,11 @@ private:
|
||||
size_t new_n = *n * 2;
|
||||
|
||||
char* new_lineptr =
|
||||
static_cast<char*>(strict_realloc(*lineptr, new_n));
|
||||
static_cast<char*>(realloc(*lineptr, new_n));
|
||||
if (new_lineptr == nullptr) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
*n = new_n;
|
||||
*lineptr = new_lineptr;
|
||||
}
|
||||
@ -942,7 +955,10 @@ private:
|
||||
size_t second_size) {
|
||||
buffer_size = first_size + second_size + 3;
|
||||
auto new_first = static_cast<char*>(
|
||||
strict_realloc(static_cast<void*>(first), buffer_size));
|
||||
realloc(static_cast<void*>(first), buffer_size));
|
||||
if (!new_first) {
|
||||
throw std::bad_alloc{};
|
||||
}
|
||||
|
||||
first = new_first;
|
||||
std::copy_n(second, second_size + 1, first + first_size);
|
||||
|
54
ssp.hpp
54
ssp.hpp
@ -640,15 +640,6 @@ inline void assert_throw_on_error_not_defined() {
|
||||
"'throw_on_error' is enabled");
|
||||
}
|
||||
|
||||
inline void* strict_realloc(void* ptr, size_t size) {
|
||||
ptr = realloc(ptr, size);
|
||||
if (!ptr) {
|
||||
throw std::bad_alloc{};
|
||||
}
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
#if __unix__
|
||||
inline ssize_t get_line_file(char** lineptr, size_t* n, FILE* stream) {
|
||||
return getline(lineptr, n, stream);
|
||||
@ -667,7 +658,13 @@ ssize_t get_line_file(char** lineptr, size_t* n, FILE* fp) {
|
||||
|
||||
if (*lineptr == nullptr || *n < sizeof(buff)) {
|
||||
size_t new_n = sizeof(buff);
|
||||
*lineptr = static_cast<char*>(strict_realloc(*lineptr, new_n));
|
||||
auto new_lineptr = static_cast<char*>(realloc(*lineptr, new_n));
|
||||
if (new_lineptr == nullptr) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
*lineptr = new_lineptr;
|
||||
*n = new_n;
|
||||
}
|
||||
|
||||
@ -681,7 +678,13 @@ ssize_t get_line_file(char** lineptr, size_t* n, FILE* fp) {
|
||||
if (*n <= buff_used + line_used) {
|
||||
size_t new_n = *n * 2;
|
||||
|
||||
*lineptr = static_cast<char*>(strict_realloc(*lineptr, new_n));
|
||||
auto new_lineptr = static_cast<char*>(realloc(*lineptr, new_n));
|
||||
if (new_lineptr == nullptr) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
|
||||
*lineptr = new_lineptr;
|
||||
*n = new_n;
|
||||
}
|
||||
|
||||
@ -2232,7 +2235,7 @@ public:
|
||||
}
|
||||
|
||||
size_t line() const {
|
||||
return reader_.line_number_ > 0 ? reader_.line_number_ - 1
|
||||
return reader_.line_number_ > 1 ? reader_.line_number_ - 1
|
||||
: reader_.line_number_;
|
||||
}
|
||||
|
||||
@ -2344,7 +2347,7 @@ public:
|
||||
reader_.next_line_converter_.set_column_mapping(column_mappings,
|
||||
header_.size());
|
||||
|
||||
if (line() == 0) {
|
||||
if (line() == 1) {
|
||||
ignore_next();
|
||||
}
|
||||
}
|
||||
@ -2827,7 +2830,8 @@ private:
|
||||
csv_data_buffer_{other.csv_data_buffer_},
|
||||
csv_data_size_{other.csv_data_size_},
|
||||
curr_char_{other.curr_char_}, crlf_{other.crlf_},
|
||||
line_number_{other.line_number_}, chars_read_{other.chars_read_},
|
||||
line_number_{other.line_number_},
|
||||
chars_read_{other.chars_read_},
|
||||
next_line_size_{other.next_line_size_} {
|
||||
other.buffer_ = nullptr;
|
||||
other.next_line_buffer_ = nullptr;
|
||||
@ -2882,13 +2886,22 @@ private:
|
||||
ssize_t get_line_buffer(char** lineptr, size_t* n,
|
||||
const char* const csv_data_buffer,
|
||||
size_t csv_data_size, size_t& curr_char) {
|
||||
if (lineptr == nullptr || n == nullptr ||
|
||||
csv_data_buffer == nullptr) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (curr_char >= csv_data_size) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (*lineptr == nullptr || *n < get_line_initial_buffer_size) {
|
||||
auto new_lineptr = static_cast<char*>(
|
||||
strict_realloc(*lineptr, get_line_initial_buffer_size));
|
||||
realloc(*lineptr, get_line_initial_buffer_size));
|
||||
if (new_lineptr == nullptr) {
|
||||
return -1;
|
||||
}
|
||||
*lineptr = new_lineptr;
|
||||
*n = get_line_initial_buffer_size;
|
||||
}
|
||||
@ -2899,7 +2912,11 @@ private:
|
||||
size_t new_n = *n * 2;
|
||||
|
||||
char* new_lineptr =
|
||||
static_cast<char*>(strict_realloc(*lineptr, new_n));
|
||||
static_cast<char*>(realloc(*lineptr, new_n));
|
||||
if (new_lineptr == nullptr) {
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
}
|
||||
*n = new_n;
|
||||
*lineptr = new_lineptr;
|
||||
}
|
||||
@ -3072,7 +3089,10 @@ private:
|
||||
size_t second_size) {
|
||||
buffer_size = first_size + second_size + 3;
|
||||
auto new_first = static_cast<char*>(
|
||||
strict_realloc(static_cast<void*>(first), buffer_size));
|
||||
realloc(static_cast<void*>(first), buffer_size));
|
||||
if (!new_first) {
|
||||
throw std::bad_alloc{};
|
||||
}
|
||||
|
||||
first = new_first;
|
||||
std::copy_n(second, second_size + 1, first + first_size);
|
||||
|
Loading…
Reference in New Issue
Block a user