[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

obstack_free(obs, addr) not portable when addr != NULL

From: Jeffrey Kegler
Subject: obstack_free(obs, addr) not portable when addr != NULL
Date: Thu, 12 Apr 2012 17:48:26 -0700

Studying the code for obstack_free(), I cannot convince myself that obstack_free(obs, addr) is C89 conformant when addr != NULL.  To determine if addr is in the current chunk, the code does pointer comparisons with the addresses of the chunk.  These are only well-defined if addr is in the chunk.  As I read Section A7.9 (C programming language, 2nd ed., p. 206) if addr is not in the chunk an implementation's behavior is undefined -- it could abend or to return a spurious positive.  In the case of a spurious positive, the pointer would be copied into the chunk's header, and C89 would not require its behavior when de-referenced to be consistent with its behavior under pointer comparison -- or even for its behavior in future pointer comparisons to be consistent with previous ones.

I recognize this is a bit of a quibble, since in current practice the pointers will all come from the arena of a single memory allocator, and comparisons will (almost?) always behave as if from a flat address space.  But C89 does not seem to require this.  The memory allocator specified for obstack COULD return addresses from multiple incomparable address spaces -- not likely, but it could.  Or a future architecture might return to the strangely segmented address spaces of yesteryear.

Possible fixes: 1)  Document that the behavior is unportable, and under what conditions it can be expected to work.  At a minimum, describe the behavior required of the memory allocator.  2.) Remove/replace the feature.

Thanks, jeffrey kegler

reply via email to

[Prev in Thread] Current Thread [Next in Thread]