Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //check later code won't crash the system
- if( buf.length() % 2 )
- return false;
- // do other stuff that shouldn't affect bufs length
- //copy 2 bytes into buf at a time, if length is odd then don't know
- //what will happen so use assert to make sure it can't damage anything
- assert( !(buf.length() % 2) );
- for( i = 0; i != buf.length(); i += 2 )
- memcpy( buf + i, data, 2 );
- /// ASSERT(condition) checks if the condition is met, and if not, calls
- /// ABORT with an error message indicating the module and line where
- /// the error occurred.
- #ifndef ASSERT
- #define ASSERT(x)
- if (!(x)) {
- char buf[2048];
- snprintf (buf, 2048, "Assertion failed in "%s", line %dn"
- "tProbable bug in software.n",
- __FILE__, __LINE__);
- ABORT (buf);
- }
- else // This 'else' exists to catch the user's following semicolon
- #endif
- /// DASSERT(condition) is just like ASSERT, except that it only is
- /// functional in DEBUG mode, but does nothing when in a non-DEBUG
- /// (optimized, shipping) build.
- #ifdef DEBUG
- # define DASSERT(x) ASSERT(x)
- #else
- # define DASSERT(x) /* DASSERT does nothing when not debugging */
- #endif
- #undef NDEBUG
Add Comment
Please, Sign In to add comment