-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Conversation
8c77fe3
to
65e4e57
Compare
PR #30804: Size comparison from b9ff894 to 65e4e57 Decreases (5 builds for cc32xx, mbed, qpg)
Full report (5 builds for cc32xx, mbed, qpg)
|
65e4e57
to
973c9cb
Compare
PR #30804: Size comparison from b9ff894 to 973c9cb Decreases (15 builds for cc13x4_26x4, cc32xx, k32w, mbed, qpg)
Full report (15 builds for cc13x4_26x4, cc32xx, k32w, mbed, qpg)
|
973c9cb
to
423de24
Compare
PR #30804: Size comparison from b9ff894 to 423de24 Increases above 0.2%:
Increases (7 builds for esp32, linux, psoc6)
Decreases (31 builds for cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, k32w, linux, mbed, psoc6, qpg)
Full report (31 builds for cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, k32w, linux, mbed, psoc6, qpg)
|
423de24
to
c0a120c
Compare
PR #30804: Size comparison from b9ff894 to c0a120c Decreases (15 builds for cc13x4_26x4, cc32xx, k32w, mbed, qpg)
Full report (15 builds for cc13x4_26x4, cc32xx, k32w, mbed, qpg)
|
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.
c0a120c
to
bed4d4a
Compare
PR #30804: Size comparison from b9ff894 to f0043de Increases above 0.2%:
Increases (15 builds for bl602, bl702, bl702l, cc13x4_26x4, linux)
Decreases (27 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, k32w, linux, mbed, qpg)
Full report (27 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, k32w, linux, mbed, qpg)
|
3139e53
to
6bcf708
Compare
PR #30804: Size comparison from 16f8d7a to 6bcf708 Decreases (2 builds for cc32xx)
Full report (2 builds for cc32xx)
|
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' {} +
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' {} +
6bcf708
to
aba4909
Compare
PR #30804: Size comparison from 16f8d7a to aba4909 Increases above 0.2%:
Increases (33 builds for bl602, bl702, bl702l, cc13x4_26x4, esp32, linux, psoc6, telink)
Decreases (82 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, k32w, linux, mbed, nrfconnect, psoc6, qpg, telink)
Full report (83 builds for bl602, bl702, bl702l, cc13x4_26x4, cc32xx, cyw30739, efr32, esp32, k32w, linux, mbed, nrfconnect, psoc6, qpg, telink)
|
The declaration
declares a mutable pointer to const C string, and so the following assignment is legal:
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:
with 2 fixes to add "inline" in constants defined in headers.