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 <jan.matyas@codasip.com>
Reviewed-on: https://review.openocd.org/c/openocd/+/8517
Reviewed-by: Antonio Borneo <borneo.antonio@gmail.com>
Tested-by: jenkins
This commit is contained in:
Jan Matyas
2024-09-30 14:55:58 +02:00
committed by Antonio Borneo
parent 114ca19f64
commit d09ff47644
4 changed files with 8 additions and 8 deletions

View File

@@ -335,7 +335,7 @@ static int gdb_putback_char(struct connection *connection, int last_char)
/* The only way we can detect that the socket is closed is the first time
* we write to it, we will fail. Subsequent write operations will
* succeed. Shudder! */
static int gdb_write(struct connection *connection, void *data, int len)
static int gdb_write(struct connection *connection, const void *data, int len)
{
struct gdb_connection *gdb_con = connection->priv;
if (gdb_con->closed) {
@@ -351,7 +351,7 @@ static int gdb_write(struct connection *connection, void *data, int len)
return ERROR_SERVER_REMOTE_CLOSED;
}
static void gdb_log_incoming_packet(struct connection *connection, char *packet)
static void gdb_log_incoming_packet(struct connection *connection, const char *packet)
{
if (!LOG_LEVEL_IS(LOG_LVL_DEBUG))
return;
@@ -384,7 +384,7 @@ static void gdb_log_incoming_packet(struct connection *connection, char *packet)
}
}
static void gdb_log_outgoing_packet(struct connection *connection, char *packet_buf,
static void gdb_log_outgoing_packet(struct connection *connection, const char *packet_buf,
unsigned int packet_len, unsigned char checksum)
{
if (!LOG_LEVEL_IS(LOG_LVL_DEBUG))
@@ -402,7 +402,7 @@ static void gdb_log_outgoing_packet(struct connection *connection, char *packet_
}
static int gdb_put_packet_inner(struct connection *connection,
char *buffer, int len)
const char *buffer, int len)
{
int i;
unsigned char my_checksum = 0;
@@ -522,7 +522,7 @@ static int gdb_put_packet_inner(struct connection *connection,
return ERROR_OK;
}
int gdb_put_packet(struct connection *connection, char *buffer, int len)
int gdb_put_packet(struct connection *connection, const char *buffer, int len)
{
struct gdb_connection *gdb_con = connection->priv;
gdb_con->busy = true;