Ignore:
Timestamp:
Sep 11, 2014, 11:32:16 AM (5 years ago)
Author:
nmedfort
Message:

Bug fix for empty file: outfile wasn't set prior to testing.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/icgrep.cpp

    r4137 r4149  
    173173    }
    174174#endif
    175 #ifdef USE_MMAP
    176     fdSrc = open(infilename, O_RDONLY);
    177     if (fdSrc == -1) {
    178         fprintf(stderr, "Error: cannot open %s for processing.\n", infilename);
    179         exit(-1);
    180     }
    181     if (fstat(fdSrc, &infile_sb) == -1) {
    182         fprintf(stderr, "Error: cannot stat %s for processing.\n", infilename);
    183         exit(-1);
    184     }
    185     if (infile_sb.st_size == 0) {
    186         if (count_only_option) fprintf(outfile, "Matching Lines%d\n", 0);
    187         exit(0);
    188     }
    189     infile_buffer = (char *) mmap(NULL, infile_sb.st_size, PROT_READ, MAP_PRIVATE, fdSrc, 0);
    190     if (infile_buffer == MAP_FAILED) {
    191         fprintf(stderr, "Error: mmap of %s failure.\n", infilename);
    192         exit(-1);
    193     }
    194 #endif
    195 
    196     if (optind >= argc) outfile = stdout;
    197     else
    198     {
     175
     176    if (optind >= argc) {
     177        outfile = stdout;
     178    }
     179    else {
    199180        outfilename = argv[optind++];
    200181        if (optind != argc)
     
    211192        }
    212193    }
     194
     195#ifdef USE_MMAP
     196    fdSrc = open(infilename, O_RDONLY);
     197    if (fdSrc == -1) {
     198        fprintf(stderr, "Error: cannot open %s for processing.\n", infilename);
     199        exit(-1);
     200    }
     201    if (fstat(fdSrc, &infile_sb) == -1) {
     202        fprintf(stderr, "Error: cannot stat %s for processing.\n", infilename);
     203        exit(-1);
     204    }
     205    if (infile_sb.st_size == 0) {
     206        if (count_only_option) fprintf(outfile, "Matching Lines: %d\n", 0);
     207        exit(0);
     208    }
     209    infile_buffer = (char *) mmap(NULL, infile_sb.st_size, PROT_READ, MAP_PRIVATE, fdSrc, 0);
     210    if (infile_buffer == MAP_FAILED) {
     211        fprintf(stderr, "Error: mmap of %s failure.\n", infilename);
     212        exit(-1);
     213    }
     214#endif
    213215
    214216    if (print_version_option)
Note: See TracChangeset for help on using the changeset viewer.