Commit f331811f authored by Li's avatar Li
Browse files

Make buffer size a const variable. Check whether gz can reach eof.

parent c9515835
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -325,9 +325,9 @@ void Chromap::LoadBarcodeWhitelist() {
  if (1) {
    gzFile barcode_whitelist_file = 
      gzopen(mapping_parameters_.barcode_whitelist_file_path.c_str(), "r"); 
    char barcode[256];

    while (gzgets(barcode_whitelist_file, barcode, sizeof(barcode)) != NULL) {
    const uint32_t barcode_buffer_size = 256;
    char barcode[barcode_buffer_size];
    while (gzgets(barcode_whitelist_file, barcode, barcode_buffer_size) != NULL) {
      size_t barcode_length = strlen(barcode);
      if (barcode[barcode_length - 1] == '\n') {
        barcode[barcode_length - 1] = '\0';
@@ -359,6 +359,9 @@ void Chromap::LoadBarcodeWhitelist() {
      assert(khash_return_code != -1 && khash_return_code != 0);
      ++num_barcodes;
    }
    if (!gzeof(barcode_whitelist_file)) {
      ExitWithMessage("ERROR: barcode whitelist file does not exist or is truncated!");
    }
    gzclose(barcode_whitelist_file);
  } else { 
    std::ifstream barcode_whitelist_file_stream(