mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2024-12-01 15:35:47 +00:00
harden SimpleIStringStream against user errors and kill operator bool()
Like this: size_t x; if(is >> x) {...} This used to return true despite x never being populated, because is was casted to bool, which is fine to shift by uninitialized, and likely returned true. Whatever.
This commit is contained in:
parent
b74c5a2986
commit
4c52a147b0
1 changed files with 6 additions and 6 deletions
|
@ -175,8 +175,8 @@ class SimpleIStringStream {
|
||||||
/*------------------------------*/
|
/*------------------------------*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* operator bool: Evaluate the stream as a boolean. Returns false if
|
* operator void*: Evaluate the stream as a boolean. Returns NULL if
|
||||||
* an error has occurred, true otherwise. (This allows the stream to
|
* an error has occurred, this otherwise. (This allows the stream to
|
||||||
* be used in a while loop like "while (stream >> var)", in the same
|
* be used in a while loop like "while (stream >> var)", in the same
|
||||||
* way as ordinary std::istringstream objects.)
|
* way as ordinary std::istringstream objects.)
|
||||||
*
|
*
|
||||||
|
@ -185,7 +185,7 @@ class SimpleIStringStream {
|
||||||
* [Return value]
|
* [Return value]
|
||||||
* False if an error has occurred, else true
|
* False if an error has occurred, else true
|
||||||
*/
|
*/
|
||||||
inline operator bool() const;
|
inline operator void*() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* operator>>: Extract a value from a stream. String extraction skips
|
* operator>>: Extract a value from a stream. String extraction skips
|
||||||
|
@ -419,10 +419,10 @@ inline SimpleIStringStream &SimpleIStringStream::operator=(
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
|
|
||||||
inline SimpleIStringStream::operator bool() const
|
inline SimpleIStringStream::operator void*() const
|
||||||
{
|
{
|
||||||
#ifdef SISS_VERIFY
|
#ifdef SISS_VERIFY
|
||||||
if (!error != bool(std_is)) {
|
if (!error != (void*)(std_is)) {
|
||||||
std::ostringstream os_offset; os_offset << (position - buffer);
|
std::ostringstream os_offset; os_offset << (position - buffer);
|
||||||
debugLog(std::string("SimpleIStringStream bool MISMATCH: us=")
|
debugLog(std::string("SimpleIStringStream bool MISMATCH: us=")
|
||||||
+ (!error ? "true" : "false") + " STL="
|
+ (!error ? "true" : "false") + " STL="
|
||||||
|
@ -432,7 +432,7 @@ inline SimpleIStringStream::operator bool() const
|
||||||
+ os_offset.str() + ")");
|
+ os_offset.str() + ")");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return !error;
|
return error ? NULL : (void*)this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*-----------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------*/
|
||||||
|
|
Loading…
Reference in a new issue