A
ais523
Consider the following program:
#include <stdlib.h>
#include <limits.h>
int main(void)
{
size_t s=SIZE_MAX;
size_t i;
char* p;
while(s--)
{
p=malloc(s);
if(p)
{
i=s;
while(i--) p=42;
free(p);
}
}
return 0;
}
This program would be incredibly slow to run, but I'm interested in
whether or not it causes UB. There seem to be implementations (I
include the operating system as part of the implementation) which would
crash if they tried to run this, due to malloc returning non-NULL when
the system doesn't actually have the memory available (which is
non-conforming behaviour AFAICT). So: Is this UB, or is it merely a
common implementation non-conformance?
#include <stdlib.h>
#include <limits.h>
int main(void)
{
size_t s=SIZE_MAX;
size_t i;
char* p;
while(s--)
{
p=malloc(s);
if(p)
{
i=s;
while(i--) p=42;
free(p);
}
}
return 0;
}
This program would be incredibly slow to run, but I'm interested in
whether or not it causes UB. There seem to be implementations (I
include the operating system as part of the implementation) which would
crash if they tried to run this, due to malloc returning non-NULL when
the system doesn't actually have the memory available (which is
non-conforming behaviour AFAICT). So: Is this UB, or is it merely a
common implementation non-conformance?