summaryrefslogtreecommitdiff
path: root/util.h
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2004-09-26 20:22:57 -0400
committerJohn Wiegley <johnw@newartisans.com>2004-09-26 20:22:57 -0400
commitf32f698d7f097234ebabe725e8f8aaa1fa740753 (patch)
tree9ff3f16305184b973d36741cbbdf88dd5384ff7b /util.h
parent17808869b29e73e8a12129e3f52d885d484936c9 (diff)
downloadfork-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.h33
1 files changed, 16 insertions, 17 deletions
diff --git a/util.h b/util.h
index f021e437..9fe115cc 100644
--- a/util.h
+++ b/util.h
@@ -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