[previous] 0752 [next] String literal passed as argument to function whose parameter is not a 'pointer to const'.
Pointers REFERENCE - ISO:C90-6.1.4 String Literals - Semantics

A string literal is of type "pointer to array of char". It is an unfortunate weakness of the C language (a result of its history), that the type is not "pointer to array of const char". The array of characters addressed by a string literal should never be modified and any attempt to do so will result in undefined behavior.

Message 0752 identifies situations where a string literal is passed as an argument to a function whose parameter is not defined as a "pointer to const".

Message 0753 identifies situations where a string literal is assigned to a pointer which is not defined as a "pointer to const".

For example:


/*PRQA S 2017,3122,3123,3204,3205,3408,3447,3602,3625 ++*/

extern void ef1(char * p);
extern void ef2(const char * p);

extern void foo(void)
{
    char       *pca = "xyz";          /* Message 0753                    */
    const char *pcb = "abc";          /*                                 */

    *pca = 'X';                       /*                Undefined        */
    *pcb = 'X';                       /* Message 0556 - Constraint Error */

    ef1("123");                       /* Message 0752                    */
    ef2("456");                       /*                                 */

    ef1(pcb);                         /* Message 0431 - Constraint Error */
}

extern char * f1(void)
{
    return "ABC";                     /* Message 0753                    */
}

extern const char * f2(void)
{
    return "XYZ";                     /*                                 */
}

See also:

QA·C Source Code Analyser 8.1.2
© 2013 Programming Research.
www.programmingresearch.com
Personality Groups | Glossary | Message Index Contents