Skip to content

Commit

Permalink
Fix invalid memory access issue in g++ builds (#228)
Browse files Browse the repository at this point in the history
* Try to use shared_ptr<CSVField> to avoid memory issues

* Run tests

* Update single include

* Also added test for empty file SEGFAULT

* diD yoU forGet to #incLude<cStrIng>
  • Loading branch information
vincentlaucsb committed May 19, 2024
1 parent 0ef1cff commit 3a3dc72
Show file tree
Hide file tree
Showing 8 changed files with 1,838 additions and 1,860 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: CMake on multiple platforms

on:
push:
branches: [ "master", "gcc-error" ]
branches: [ "master", "memory-fix-gcc" ]
pull_request:
branches: [ "master" ]

Expand Down
2 changes: 1 addition & 1 deletion include/csv.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
CSV for C++, version 2.2.1
CSV for C++, version 2.2.2
https://github.com/vincentlaucsb/csv-parser
MIT License
Expand Down
5 changes: 0 additions & 5 deletions include/internal/csv_row.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,7 @@ namespace csv {
}

CSV_INLINE CSVRow::iterator::pointer CSVRow::iterator::operator->() const {
// Using CSVField * as pointer type causes segfaults in MSVC debug builds
#ifdef _MSC_BUILD
return this->field;
#else
return this->field.get();
#endif
}

CSV_INLINE CSVRow::iterator& CSVRow::iterator::operator++() {
Expand Down
8 changes: 0 additions & 8 deletions include/internal/csv_row.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,15 +337,7 @@ namespace csv {
#ifndef DOXYGEN_SHOULD_SKIP_THIS
using value_type = CSVField;
using difference_type = int;

// Using CSVField * as pointer type causes segfaults in MSVC debug builds
// but using shared_ptr as pointer type won't compile in g++
#ifdef _MSC_BUILD
using pointer = std::shared_ptr<CSVField>;
#else
using pointer = CSVField * ;
#endif

using reference = CSVField & ;
using iterator_category = std::random_access_iterator_tag;
#endif
Expand Down

0 comments on commit 3a3dc72

Please sign in to comment.