J
jay
#include <stdio.h>
#include <limits.h>
int main(void)
{
char arrc[UINT_MAX] = {'a'};
printf("arrc = %s\n", arrc);
return 0;
}
================ OUTPUT ==============
[myhome]$ gcc -ansi -pedantic -Wall -Wextra test2.c
test2.c: In function `main':
test2.c:6: error: size of array `arrc' is too large
test2.c:6: warning: unused variable `arrc'
I am using gcc 3.4.6 on Solaris 10. I completely understand the error thatarray size should be below some limit but what is that limit ? Same happens if I try to malloc(UINT_MAX), it fails.
2nd, I am writing a program where input is taken from command-line (think argv[1]). User can input anything of any size. Imagine user inputs a string too long, just like UINT_MAX was way bigger for malloc(), and I try to do strlen() on it ? How will I know/check that string is too long so that I can bail out on time ?
I read about strlen() in C standard (n1570) in 6.24.6.3, it does not have any error condition associated with it.
#include <limits.h>
int main(void)
{
char arrc[UINT_MAX] = {'a'};
printf("arrc = %s\n", arrc);
return 0;
}
================ OUTPUT ==============
[myhome]$ gcc -ansi -pedantic -Wall -Wextra test2.c
test2.c: In function `main':
test2.c:6: error: size of array `arrc' is too large
test2.c:6: warning: unused variable `arrc'
I am using gcc 3.4.6 on Solaris 10. I completely understand the error thatarray size should be below some limit but what is that limit ? Same happens if I try to malloc(UINT_MAX), it fails.
2nd, I am writing a program where input is taken from command-line (think argv[1]). User can input anything of any size. Imagine user inputs a string too long, just like UINT_MAX was way bigger for malloc(), and I try to do strlen() on it ? How will I know/check that string is too long so that I can bail out on time ?
I read about strlen() in C standard (n1570) in 6.24.6.3, it does not have any error condition associated with it.