My version of strtol() doesn't detect errors either. Pass it a huge integer
and it scans to the end of the string and returns a garbage result. (This is
gcc on Linux).
It's actually glibc on Linux. However, my copy correctly returns
LONG_MAX and sets errno to ERANGE as required by the standard. So I
suggest you are not using it properly or are using a very buggy old version.
[markg@cpa-re-test ~]16$ cat t.c
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <string.h>
int main(void)
{
char *src = "999999999999999999999999999999";
char *end;
long v = strtol(src,&end,0);
fprintf(stdout,"v-correct=%d, out-of-range=%d, scanned-correct=%d\n",
v==LONG_MAX,errno==ERANGE,(end-src)==strlen(src));
return 0;}
[markg@cpa-re-test ~]17$ gcc t.c -ansi -pedantic -Wall -W
t.c: In function `main':
t.c:12: warning: comparison between signed and unsigned
[markg@cpa-re-test ~]18$ ./a.out
v-correct=1, out-of-range=1, scanned-correct=1
[markg@cpa-re-test ~]19$