This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: malloc attributes and realloc


"Zack Weinberg" <zack@codesourcery.com> writes:

| Gabriel Dos Reis <gdr@integrable-solutions.net> writes:
| 
| > | This isn't directly relevant to the current thread, but another aspect of
| > | malloc-like functions came up recently: the memory they return is writable.
| > | I.e., if char *p was returned by an attribute(malloc) function, then
| > |   if (*p != 'a')
| > |     *p = 'a';
| > | 
| > | can be safely optimized into
| > |   *p = 'a';
| >
| > That transformation caanot be applied for pointers returned by
| > realloc, in general.
| 
| Huh? Are you asserting that realloc may return a pointer to read-only
| memory?

No, I'm saying that the test

    if (*p != 'a')

cannot not be "skipped" (or turned into true) because there might be a
data there that actually is an 'a'.

-- Gaby


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]