mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-10 02:40:40 +03:00
configure.ac: enable -Wwrite-strings
As discussed in bug #185 [1], const strings should be protected from being overwritten. This change adds -Wwrite-strings to the compiler warning flags and fixes resulting warnings by making static strings const. [1] https://github.com/obgm/libcoap/issues/185
This commit is contained in:
1 parent
9f68329f70
commit
a2d263356e
6 files changed
+9
-8
No files matched your search
@@ -137,6 +137,7 @@ WARNING_CFLAGS="\
|
||||
-Wswitch-default \
|
||||
-Wswitch-enum \
|
||||
-Wunused \
|
||||
-Wwrite-strings \
|
||||
"
|
||||
|
||||
# check whether or not the compiler supports -Wlogical-op (clang does not...)
|
||||
|
||||
+2
-2
@@ -559,7 +559,7 @@ usage( const char *program, const char *version) {
|
||||
|
||||
typedef struct {
|
||||
unsigned char code;
|
||||
char *media_type;
|
||||
const char *media_type;
|
||||
} content_type_t;
|
||||
|
||||
static void
|
||||
@@ -968,7 +968,7 @@ cmdline_input_from_file(char *filename, str *buf) {
|
||||
|
||||
static method_t
|
||||
cmdline_method(char *arg) {
|
||||
static char *methods[] =
|
||||
static const char *methods[] =
|
||||
{ 0, "get", "post", "put", "delete", "fetch", "patch", "ipatch", 0};
|
||||
unsigned char i;
|
||||
|
||||
|
||||
+1
-1
@@ -132,7 +132,7 @@ struct coap_session_t;
|
||||
* @return A zero-terminated string describing the error, or @c NULL if not
|
||||
* found.
|
||||
*/
|
||||
char *coap_response_phrase(unsigned char code);
|
||||
const char *coap_response_phrase(unsigned char code);
|
||||
|
||||
#define COAP_ERROR_PHRASE_LENGTH 32 /**< maximum length of error phrase */
|
||||
|
||||
|
||||
+2
-2
@@ -71,7 +71,7 @@ coap_set_log_level(coap_log_t level) {
|
||||
}
|
||||
|
||||
/* this array has the same order as the type log_t */
|
||||
static char *loglevels[] = {
|
||||
static const char *loglevels[] = {
|
||||
"EMRG", "ALRT", "CRIT", "ERR", "WARN", "NOTE", "INFO", "DEBG"
|
||||
};
|
||||
|
||||
@@ -265,7 +265,7 @@ coap_print_addr(const struct coap_address_t *addr, unsigned char *buf, size_t le
|
||||
/** Returns a textual description of the message type @p t. */
|
||||
static const char *
|
||||
msg_type_string(uint16_t t) {
|
||||
static char *types[] = { "CON", "NON", "ACK", "RST", "???" };
|
||||
static const char *types[] = { "CON", "NON", "ACK", "RST", "???" };
|
||||
|
||||
return types[min(t, sizeof(types)/sizeof(char *) - 1)];
|
||||
}
|
||||
|
||||
@@ -1426,7 +1426,7 @@ coap_new_error_response(coap_pdu_t *request, unsigned char code,
|
||||
uint16_t opt_type = 0; /* used for calculating delta-storage */
|
||||
|
||||
#if COAP_ERROR_PHRASE_LENGTH > 0
|
||||
char *phrase = coap_response_phrase(code);
|
||||
const char *phrase = coap_response_phrase(code);
|
||||
|
||||
/* Need some more space for the error phrase and payload start marker */
|
||||
if (phrase)
|
||||
|
||||
@@ -344,7 +344,7 @@ coap_get_data(coap_pdu_t *pdu, size_t *len, uint8_t **data) {
|
||||
#ifndef SHORT_ERROR_RESPONSE
|
||||
typedef struct {
|
||||
unsigned char code;
|
||||
char *phrase;
|
||||
const char *phrase;
|
||||
} error_desc_t;
|
||||
|
||||
/* if you change anything here, make sure, that the longest string does not
|
||||
@@ -376,7 +376,7 @@ error_desc_t coap_error[] = {
|
||||
{ 0, NULL } /* end marker */
|
||||
};
|
||||
|
||||
char *
|
||||
const char *
|
||||
coap_response_phrase(unsigned char code) {
|
||||
int i;
|
||||
for (i = 0; coap_error[i].code; ++i) {
|
||||
|
||||
Reference in new issue
Block a user