Changeset 3c6cba18a654f50a87118dfd7fb1e7117ac02f43

Show
Ignore:
Timestamp:
05/25/10 13:32:34 (4 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1274794354 +0000
git-parent:

[8a9cddfb29f89ab8c272465be08b0bc5f54dd896]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1274794354 +0000
Message:

fixes #285

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/stratcon_datastore.c

    r6cd90c1 r3c6cba1  
    10451045  } 
    10461046  len = st.st_size; 
    1047   buff = mmap(NULL, len, PROT_READ, MAP_PRIVATE, ij->fd, 0); 
    1048   if(buff == (void *)-1) { 
    1049     noitL(noit_error, "mmap(%d, %d)(%s) => %s\n", (int)len, ij->fd, 
    1050           ij->filename, strerror(errno)); 
    1051     assert(buff != (void *)-1); 
    1052   } 
    1053   lcp = buff; 
    1054   while(lcp < (buff + len) && 
    1055         NULL != (cp = strnstrn("\n", 1, lcp, len - (lcp-buff)))) { 
    1056     next = calloc(1, sizeof(*next)); 
    1057     next->data = malloc(cp - lcp + 1); 
    1058     memcpy(next->data, lcp, cp - lcp); 
    1059     next->data[cp - lcp] = '\0'; 
    1060     if(!head) head = next; 
    1061     if(last) last->next = next; 
    1062     last = next; 
    1063     lcp = cp + 1; 
    1064   } 
    1065   munmap((void *)buff, len); 
     1047  if(len > 0) { 
     1048    buff = mmap(NULL, len, PROT_READ, MAP_PRIVATE, ij->fd, 0); 
     1049    if(buff == (void *)-1) { 
     1050      noitL(noit_error, "mmap(%d, %d)(%s) => %s\n", (int)len, ij->fd, 
     1051            ij->filename, strerror(errno)); 
     1052      assert(buff != (void *)-1); 
     1053    } 
     1054    lcp = buff; 
     1055    while(lcp < (buff + len) && 
     1056          NULL != (cp = strnstrn("\n", 1, lcp, len - (lcp-buff)))) { 
     1057      next = calloc(1, sizeof(*next)); 
     1058      next->data = malloc(cp - lcp + 1); 
     1059      memcpy(next->data, lcp, cp - lcp); 
     1060      next->data[cp - lcp] = '\0'; 
     1061      if(!head) head = next; 
     1062      if(last) last->next = next; 
     1063      last = next; 
     1064      lcp = cp + 1; 
     1065    } 
     1066    munmap((void *)buff, len); 
     1067  } 
    10661068  close(ij->fd); 
    10671069  return head;