Changeset 3d8702c in tol


Ignore:
Timestamp:
Aug 12, 2009, 5:04:58 PM (17 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
bfe66f2
Parents:
d3756e3
Message:

Fixed bug in both methods BText::GetLine. When file is eof length_ is set to -1 and an invalid writting access is done at buffer_[-1]

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@1220 be4846ae-f051-483a-831f-b64e7d08527f

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tol/bbasic/txtalgeb.cpp

    rd3756e3 r3d8702c  
    15581558  }
    15591559  length_ = 0;
    1560   BChar ch  = '\0';
     1560  BChar ch  = 1;
    15611561  bool untilIsLF = until=='\n';
    1562   for(;(length_<=maxChars)&&(ch!=until)&&(!is.eof()); length_++)
     1562  for(;(length_<=maxChars)&&ch&&(ch!=until)&&(!is.eof()); length_++)
    15631563  {
    15641564    is.get(ch);
    … …  
    15721572    buffer_[length_] = ch;
    15731573  }
    1574   if(ch==until) { length_--; }
    1575   if(ch=='\0')  { length_--; }
     1574  if((ch==until)&&length_) { length_--; }
    15761575  buffer_[length_] = '\0';
    15771576
    … …  
    15981597  }
    15991598  length_ = 0;
    1600   BChar ch  = '\0', c;
     1599  BChar ch  = 1, c;
    16011600  bool untilIsLF = until=='\n';
    1602   for(;(length_<=maxChars)&&(ch!=until)&&(!feof(file)); length_++)
     1601  for(;(length_<=maxChars)&&ch&&(ch!=until)&&(!feof(file)); length_++)
    16031602  {
    16041603    ch = fgetc(file);
    … …  
    16121611    buffer_[length_] = ch;
    16131612  }
    1614   if(ch==until) { length_--; }
    1615   if(ch=='\0')  { length_--; }
     1613  if((ch==until)&&length_) { length_--; }
    16161614  buffer_[length_] = '\0';
    16171615}
Note: See TracChangeset for help on using the changeset viewer.