https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94169

            Bug ID: 94169
           Summary: warn for modifying getenv() result
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

Bug 94157 was caused by modifying the string pointed to by the value returned
from getenv(), which is undefined according to both C and POSIX.  C11 says in
7.22.4.8, p4:

  The getenv function returns a pointer to a string associated with the matched
list member. The string pointed to shall not be modified by the program, but
may be overwritten by a subsequent call to the getenv function.

It would be helpful if GCC issued a warning for attempts to modify the returned
string.  This could be done by extending -Wstringop-overflow.

Reply via email to