diff options
author | John Wiegley <johnw@newartisans.com> | 2004-09-26 20:22:57 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2004-09-26 20:22:57 -0400 |
commit | f32f698d7f097234ebabe725e8f8aaa1fa740753 (patch) | |
tree | 9ff3f16305184b973d36741cbbdf88dd5384ff7b /util.h | |
parent | 17808869b29e73e8a12129e3f52d885d484936c9 (diff) | |
download | fork-ledger-f32f698d7f097234ebabe725e8f8aaa1fa740753.tar.gz fork-ledger-f32f698d7f097234ebabe725e8f8aaa1fa740753.tar.bz2 fork-ledger-f32f698d7f097234ebabe725e8f8aaa1fa740753.zip |
added safety to READ_INT macro
Diffstat (limited to 'util.h')
-rw-r--r-- | util.h | 33 |
1 files changed, 16 insertions, 17 deletions
@@ -16,23 +16,22 @@ inline char peek_next_nonws(std::istream& in) { return c; } -#define READ_INTO(str, targ, size, var, cond) { \ - char * _p = targ; \ - var = str.peek(); \ - while (! str.eof() && (cond)) { \ - str.get(var); \ - if (str.eof()) \ - break; \ - if (var == '\\') { \ - str.get(var); \ - if (in.eof()) \ - break; \ - } \ - *_p++ = var; \ - var = str.peek(); \ - } \ - assert(_p < targ + ((size) - 1)); \ - *_p = '\0'; \ +#define READ_INTO(str, targ, size, var, cond) { \ + char * _p = targ; \ + var = str.peek(); \ + while (! str.eof() && (cond) && _p - targ < size) { \ + str.get(var); \ + if (str.eof()) \ + break; \ + if (var == '\\') { \ + str.get(var); \ + if (in.eof()) \ + break; \ + } \ + *_p++ = var; \ + var = str.peek(); \ + } \ + *_p = '\0'; \ } #endif // _UTIL_H |