Skip to content

Commit d09ff47

Browse files
JanMatCodasipborneoa
authored andcommitted
gdb_server: Improve const correctness
On several packet-handling functions, add "const" to arguments that represent read-only packet buffers. For instance on GCC 13.2.0, this code: const char *some_packet = "..."; gdb_put_packet(conn, some_packet, strlen(some_packet)); would prior to the fix produce warning: passing argument 2 of ‘gdb_put_packet’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers] Change-Id: Idb62f57d37ed323c39de38982e57afdd3882e280 Signed-off-by: Jan Matyas <[email protected]> Reviewed-on: https://review.openocd.org/c/openocd/+/8517 Reviewed-by: Antonio Borneo <[email protected]> Tested-by: jenkins
1 parent 114ca19 commit d09ff47

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

src/helper/log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ void log_socket_error(const char *socket_desc)
505505
* Find the first non-printable character in the char buffer, return a pointer to it.
506506
* If no such character exists, return NULL.
507507
*/
508-
char *find_nonprint_char(char *buf, unsigned int buf_len)
508+
const char *find_nonprint_char(const char *buf, unsigned int buf_len)
509509
{
510510
for (unsigned int i = 0; i < buf_len; i++) {
511511
if (!isprint(buf[i]))

src/helper/log.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ char *alloc_vprintf(const char *fmt, va_list ap);
8989
char *alloc_printf(const char *fmt, ...)
9090
__attribute__ ((format (PRINTF_ATTRIBUTE_FORMAT, 1, 2)));
9191

92-
char *find_nonprint_char(char *buf, unsigned int buf_len);
92+
const char *find_nonprint_char(const char *buf, unsigned int buf_len);
9393

9494
extern int debug_level;
9595

src/server/gdb_server.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ static int gdb_putback_char(struct connection *connection, int last_char)
335335
/* The only way we can detect that the socket is closed is the first time
336336
* we write to it, we will fail. Subsequent write operations will
337337
* succeed. Shudder! */
338-
static int gdb_write(struct connection *connection, void *data, int len)
338+
static int gdb_write(struct connection *connection, const void *data, int len)
339339
{
340340
struct gdb_connection *gdb_con = connection->priv;
341341
if (gdb_con->closed) {
@@ -351,7 +351,7 @@ static int gdb_write(struct connection *connection, void *data, int len)
351351
return ERROR_SERVER_REMOTE_CLOSED;
352352
}
353353

354-
static void gdb_log_incoming_packet(struct connection *connection, char *packet)
354+
static void gdb_log_incoming_packet(struct connection *connection, const char *packet)
355355
{
356356
if (!LOG_LEVEL_IS(LOG_LVL_DEBUG))
357357
return;
@@ -384,7 +384,7 @@ static void gdb_log_incoming_packet(struct connection *connection, char *packet)
384384
}
385385
}
386386

387-
static void gdb_log_outgoing_packet(struct connection *connection, char *packet_buf,
387+
static void gdb_log_outgoing_packet(struct connection *connection, const char *packet_buf,
388388
unsigned int packet_len, unsigned char checksum)
389389
{
390390
if (!LOG_LEVEL_IS(LOG_LVL_DEBUG))
@@ -402,7 +402,7 @@ static void gdb_log_outgoing_packet(struct connection *connection, char *packet_
402402
}
403403

404404
static int gdb_put_packet_inner(struct connection *connection,
405-
char *buffer, int len)
405+
const char *buffer, int len)
406406
{
407407
int i;
408408
unsigned char my_checksum = 0;
@@ -522,7 +522,7 @@ static int gdb_put_packet_inner(struct connection *connection,
522522
return ERROR_OK;
523523
}
524524

525-
int gdb_put_packet(struct connection *connection, char *buffer, int len)
525+
int gdb_put_packet(struct connection *connection, const char *buffer, int len)
526526
{
527527
struct gdb_connection *gdb_con = connection->priv;
528528
gdb_con->busy = true;

src/server/gdb_server.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ int gdb_target_add_all(struct target *target);
2828
int gdb_register_commands(struct command_context *command_context);
2929
void gdb_service_free(void);
3030

31-
int gdb_put_packet(struct connection *connection, char *buffer, int len);
31+
int gdb_put_packet(struct connection *connection, const char *buffer, int len);
3232

3333
int gdb_get_actual_connections(void);
3434

0 commit comments

Comments
 (0)