Date: 2010nov25
Updated: 2019mar18
Language: C++
Product: Visual C++
Q. Debug Assertion fails: Expression:(unsigned)(c+1) <= 256
Why is my program getting this debug assertion failed:
Debug Assertion failed!
File: isctype.c
Line: 56
Expression:(unsigned)(c+1) <= 256
A. Probably because you are reading beyond your buffer.
This isn't a problem with VC++ ... it is helping you out.
For example this will cause this problem:
char buf[] = "abc";
for (char *p = buf;;p++) // Loop forever (bug on purpose)
{
if (isalnum(*p)) printf("alnum");
}
As you can see this faulty code will do isalnum(buf[5]) which is beyond
what we have allocated. isalnum() or isdigit() or other is* function
will assert letting us know.