Skip to content

fix bug in read_file_binary(FILE *fp, std::vector<uint8_t> &fileBufferBytes)#1821

Merged
alecjacobson merged 2 commits intolibigl:mainfrom
fabyday:fclose_fixed
Jul 20, 2021
Merged

fix bug in read_file_binary(FILE *fp, std::vector<uint8_t> &fileBufferBytes)#1821
alecjacobson merged 2 commits intolibigl:mainfrom
fabyday:fclose_fixed

Conversation

@fabyday
Copy link
Copy Markdown
Contributor

@fabyday fabyday commented Jun 1, 2021

Fixes # .

add fclose(File* fp).

from in file_utils.cpp

  if (!ferror(fp)) {
    fseek(fp, 0, SEEK_END);
    size_t sizeBytes = ftell(fp);
    fseek(fp, 0, SEEK_SET);
    fileBufferBytes.resize(sizeBytes);

    if (fread((char*)fileBufferBytes.data(), 1, sizeBytes, fp) == sizeBytes) 
      return;
  }

to

  if (!ferror(fp)) {
    fseek(fp, 0, SEEK_END);
    size_t sizeBytes = ftell(fp);
    fseek(fp, 0, SEEK_SET);
    fileBufferBytes.resize(sizeBytes);

    if (fread((char*)fileBufferBytes.data(), 1, sizeBytes, fp) == sizeBytes) {
      fclose(fp);
      return;
    }
  }

Checklist

  • All changes meet libigl style-guidelines.
  • Adds new .cpp file.
  • Adds corresponding unit test.
  • This is a minor change.

@alecjacobson alecjacobson merged commit 957dcf3 into libigl:main Jul 20, 2021
@jdumas jdumas added the bug label Jul 20, 2021
@jdumas jdumas added this to the v3.0.0 milestone Jul 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants