Skip to content

Commit

Permalink
Fix seg fault when memorymapped handles files that end exactly at the…
Browse files Browse the repository at this point in the history
… end of page
  • Loading branch information
RuoshiZhang authored and milot-mirdita committed Nov 23, 2022
1 parent 19dce03 commit 712f288
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/util/convertalignments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ std::map<unsigned int, unsigned int> readKeyToSet(const std::string& file) {

MemoryMapped lookup(file, MemoryMapped::WholeFile, MemoryMapped::SequentialScan);
char* data = (char *) lookup.getData();
char* end = data + lookup.mappedSize();
const char* entry[255];
while (*data != '\0') {
while (data < end && *data != '\0') {
const size_t columns = Util::getWordsOfLine(data, entry, 255);
if (columns < 3) {
Debug(Debug::WARNING) << "Not enough columns in lookup file " << file << "\n";
Expand All @@ -125,8 +126,9 @@ std::map<unsigned int, std::string> readSetToSource(const std::string& file) {

MemoryMapped source(file, MemoryMapped::WholeFile, MemoryMapped::SequentialScan);
char* data = (char *) source.getData();
char* end = data + source.mappedSize();
const char* entry[255];
while (*data != '\0') {
while (data < end && *data != '\0') {
const size_t columns = Util::getWordsOfLine(data, entry, 255);
if (columns < 2) {
Debug(Debug::WARNING) << "Not enough columns in lookup file " << file << "\n";
Expand Down
3 changes: 2 additions & 1 deletion src/util/gff2db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ int gff2db(int argc, const char **argv, const Command &command) {
EXIT(EXIT_FAILURE);
}
char *data = (char *) file.getData();
char* end = data + file.mappedSize();
size_t idx = 0;
while (*data != '\0') {
while (data < end && *data != '\0') {
// line is a comment or empty
if (*data == '#' || *data == '\n') {
data = Util::skipLine(data);
Expand Down

0 comments on commit 712f288

Please sign in to comment.