Exactly! That's why once virtual memory is allocated, malloc() is allowed to consider the operation successful. The standard does not care at all whether it is virtual memory allocation or physical memory allocation. It is completely unspecified in the standard what sort of memory must be allocated. So no spec in the standard is being violated by returning non-null pointer for virtual memory allocation.
The malloc() function requests memory from the kernel using mmap(). If mmap() returns successfully, it means that the kernel is saying that the memory is allocated. So from malloc()'s perspective the memory allocation has been successful and it must return a non-null pointer to the caller. The standard does not require malloc() to distrust what the kernel said and try to actually write to that memory to double-check if there is any physical memory mapped to it or not. The standard also does not impose anything on the kernel. I see no section of the standard being violated here.
Section 7.22.3.1:
The order and contiguity of storage allocated by successive calls to the aligned_alloc, calloc, malloc, and realloc functions is unspecified. The pointer returned if the allocation succeeds is suitably aligned so that it may be assigned to a pointer to any type of object with a fundamental alignment requirement and then used to access such an object or an array of such objects in the space allocated (until the space is explicitly deallocated). The lifetime of an allocated object extends from the allocation until the deallocation. Each such allocation shall yield a pointer to an object disjoint from any other object. The pointer returned points to the start (lowest byte address) of the allocated space. If the space cannot be allocated, a null pointer is returned. If the size of the space requested is zero, the behavior is implementation-defined: either a null pointer is returned, or the behavior is as if the size were some nonzero value, except that the returned pointer shall not be used to access an object.
Section 7.22.3.4:
The malloc function allocates space for an object whose size is specified by size and whose value is indeterminate.
You can't be serious about "every part". This definitely does not violate section 1.1 which only talks about the scope of the standard. It also definitely does not violate 1.2 which talks about what is not within the scope of the standard.
So once again, can you cite the exact section number from the standard that you think is being violated here?
> I find it surprising how we have a functioning society with such underfinanced and overworked police, even in the well to do urban areas.
At the risk of being downvoted, I feel compelled to offer a foreigner's perspective here. As a foreigner who has lived in Bangalore, Mysore, Hyderabad, and Mumbai for 2 to 6 months many times, I have to agree with the other commenter that I did not find a functioning society. Things I saw during my visits:
- Cops refusing to file a report after a theft.
- No medical or police help during accidents. It's up to the untrained passers-by to administer some form of first aid and take an injured person to medical care facility.
- Motorcycle riders driving on sidewalks.
- Cars driving on the wrong side of the road.
- Drivers not yielding to pedestrians at crosswalks.
- Tuk-tuks refusing rides in gross violation of government regulations.
- Damage and pilferage of public property in Indian Railways.
- Eunuchs extorting money from unsuspecting people in broad daylight.
Some of these things are not exceptions but the rule. This does not consititute a functioning society per my expectations and standard of living. This is a total breakdown of law, order, civility, decency, and courtesy in society.