Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix improperly mutable pointers to string constants #30804

Merged
merged 3 commits into from
Dec 5, 2023

Commits on Dec 4, 2023

  1. Fix improperly mutable pointers to string constants

    The declaration
    
      const char * kStringConstant = "value";
    
    declares a mutable pointer to const C string, and so the following
    assignment is legal:
    
      kStringConstant = "other value";
    
    Obviously this is not desired. Declaring as "const char * const" avoids
    this, but this declares an unnecessary pointer.
    
    Change these declarations to "const(expr) char []".
    
    These edits were made by the following command:
    
    find . -name .git -prune -o -name .environment -prune -o -name third_party -prune -o -name zzz_generated -prune -o -name out -prune -o -type f \( -name '*.cpp' -o -name '*.h' \) -exec sed -i 's,^\( *\)\(static \|extern \|\)\(inline \|\)\(constexpr \|\)const char *\* * k\([A-Z][^][ ;()]*\)\( \|;\),\1\2\3\4const char k\5[]\6,g; s,^\([^()]*\)constexpr const char k\([^()]*\)\( \|;\),\1constexpr char k\2\3,g; s,^\(  *\)const\(expr\|\) char \([^()]*\)\[\] *= ",\1static const\2 char \3[] = ",g' {} +
    
    with 2 fixes to add "inline" in constants defined in headers.
    mspang committed Dec 4, 2023
    Configuration menu
    Copy the full SHA
    1129dd4 View commit details
    Browse the repository at this point in the history

Commits on Dec 5, 2023

  1. Fix more mutable string constants

    Fix static variables inside functions not named in kConstantNamingStyle:
    
    find . -name .git -prune -o -name .environment -prune -o -name third_party -prune -o -name zzz_generated -prune -o -name out -prune -o -type f \( -name '*.cpp' -o -name '*.h' \) -exec sed -i 's,^\( *\)\(static \|extern \)\(inline \|\)\(constexpr \|\)const char *\* * \([^][ ;()]*\)\( *= *"\|;\),\1\2\3\4const char \5[]\6,g' {} +
    
    Fix file scoped variables not named named in kConstantNamingStyle:
    
    find . -name .git -prune -o -name .environment -prune -o -name third_party -prune -o -name zzz_generated -prune -o -name out -prune -o -type f \( -name '*.cpp' -o -name '*.h' \) -exec sed -i 's,^\(\)\(static \|extern \|\)\(inline \|\)\(constexpr \|\)const char *\* * \([^][ ;()]*\)\( *= *"\|;\),\1\2\3\4const char \5[]\6,g' {} +
    mspang committed Dec 5, 2023
    Configuration menu
    Copy the full SHA
    b6c264a View commit details
    Browse the repository at this point in the history
  2. Also fix objc++

    find . -name .git -prune -o -name .environment -prune -o -name third_party -prune -o -name zzz_generated -prune -o -name out -prune -o -type f \( -name '*.cpp' -o -name '*.h' -o -name '*.mm' \) -exec sed -i 's,^\( *\)\(static \|extern \|\)\(inline \|\)\(constexpr \|\)const char *\* * k\([A-Z][^][ ;()]*\)\( \|;\),\1\2\3\4const char k\5[]\6,g; s,^\([^()]*\)constexpr const char k\([^()]*\)\( \|;\),\1constexpr char k\2\3,g; s,^\(  *\)const\(expr\|\) char \([^()]*\)\[\] *= ",\1static const\2 char \3[] = ",g' {} +
    mspang committed Dec 5, 2023
    Configuration menu
    Copy the full SHA
    aba4909 View commit details
    Browse the repository at this point in the history