JDK-6625327 : usage of unsafe literal string conversion to 'char *' breaks the build on Linux with GCC 4.2
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2007-11-02
  • Updated: 2010-05-11
  • Resolved: 2008-08-06
Related Reports
Duplicate :  
Relates :  
Description
GCC 4.2 is stricter in literal strings to char pointers conversion: now one can only convert literal strings to 'const char *', conversion to 'char *' is prohibited. This affects the build of the JDK when GCC 4.2 or higher is used on linux: src/os/linux/vm/jvm_linux.cpp and src/os/linux/vm/os_linux.cpp contain such unsafe conversions, which causes the build to fail.
Also, I found another problem which might lead to compliation failure. See comments for details.

Comments
SUGGESTED FIX See the patches in the attachment. const_strings.patch is simpler, but it uses const_casts which is not a good idea in general (although it is safe to use here). const_strings_cleaner.patch is more complicated because it tries to change the signatures of the getters/setters of the libpthread_version field, and there is some ugliness with creating a new temporary 'const char *' variable.
02-11-2007

EVALUATION To fix the problem we need to use const qualifier in types of the variables which get assigned to the literal strings or use the const_cast (but checking first that it is safe to use). *** (#1 of 1): [ UNSAVED ] ###@###.###
02-11-2007