Gprof: Fix strchr discarded qualifier call
This patch fixes a discarded qualifier call in gprof by ensuring the result of strrchr is stored in a const char *.
This patch addresses an issue in gprof where the return value of strrchr (which is a const char *) was being assigned to a non-const char *. The patch modifies gprof/source.c to ensure const correctness in the annotate_source function. H.J. Lu suggests combining this patch with another related patch set from Calvin Owens.
- proposer
Agrees with the patch and suggests combining it with another patch set from Calvin Owens.
“We should combine this strrchr patch set with the patch set from Calvin Owens <calvin@wbinvd.org>: https://patchwork.sourceware.org/project/binutils/list/?series=60290”
In Details
This patch modifies gprof/source.c to correct the assignment of the return value of strrchr. The strrchr function, when called on a const char *, returns a const char *. The original code was assigning this value to a non-const char *, which discards the const qualifier. The patch fixes this by declaring name_only as const char *. The related patch series mentioned may address similar issues or other improvements to gprof.
For Context
The strrchr function finds the last occurrence of a character in a string. gprof is a program profiling tool that helps developers understand where their program spends its time. This patch ensures that gprof correctly handles constant strings when using strrchr, avoiding potential issues if the program attempts to modify a string that should not be changed. The suggestion to combine this patch with another indicates possible related work or dependencies between the two.