|
From: openocd-gerrit <ope...@us...> - 2024-10-20 09:25:54
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Main OpenOCD repository".
The branch, master has been updated
via d09ff476446a5403e556476b41a5a3c9bdf0a706 (commit)
from 114ca19f64d8af5365ecf171cc2adc45a763a406 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit d09ff476446a5403e556476b41a5a3c9bdf0a706
Author: Jan Matyas <jan...@co...>
Date: Mon Sep 30 14:55:58 2024 +0200
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...@co...>
Reviewed-on: https://review.openocd.org/c/openocd/+/8517
Reviewed-by: Antonio Borneo <bor...@gm...>
Tested-by: jenkins
diff --git a/src/helper/log.c b/src/helper/log.c
index 62ba4da4c..9ad00ce62 100644
--- a/src/helper/log.c
+++ b/src/helper/log.c
@@ -505,7 +505,7 @@ void log_socket_error(const char *socket_desc)
* Find the first non-printable character in the char buffer, return a pointer to it.
* If no such character exists, return NULL.
*/
-char *find_nonprint_char(char *buf, unsigned int buf_len)
+const char *find_nonprint_char(const char *buf, unsigned int buf_len)
{
for (unsigned int i = 0; i < buf_len; i++) {
if (!isprint(buf[i]))
diff --git a/src/helper/log.h b/src/helper/log.h
index 0f11cfa9a..dc8df6fbb 100644
--- a/src/helper/log.h
+++ b/src/helper/log.h
@@ -89,7 +89,7 @@ char *alloc_vprintf(const char *fmt, va_list ap);
char *alloc_printf(const char *fmt, ...)
__attribute__ ((format (PRINTF_ATTRIBUTE_FORMAT, 1, 2)));
-char *find_nonprint_char(char *buf, unsigned int buf_len);
+const char *find_nonprint_char(const char *buf, unsigned int buf_len);
extern int debug_level;
diff --git a/src/server/gdb_server.c b/src/server/gdb_server.c
index c1e5e268f..579a388d2 100644
--- a/src/server/gdb_server.c
+++ b/src/server/gdb_server.c
@@ -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;
diff --git a/src/server/gdb_server.h b/src/server/gdb_server.h
index 4288ceb87..1a626ebd9 100644
--- a/src/server/gdb_server.h
+++ b/src/server/gdb_server.h
@@ -28,7 +28,7 @@ int gdb_target_add_all(struct target *target);
int gdb_register_commands(struct command_context *command_context);
void gdb_service_free(void);
-int gdb_put_packet(struct connection *connection, char *buffer, int len);
+int gdb_put_packet(struct connection *connection, const char *buffer, int len);
int gdb_get_actual_connections(void);
-----------------------------------------------------------------------
Summary of changes:
src/helper/log.c | 2 +-
src/helper/log.h | 2 +-
src/server/gdb_server.c | 10 +++++-----
src/server/gdb_server.h | 2 +-
4 files changed, 8 insertions(+), 8 deletions(-)
hooks/post-receive
--
Main OpenOCD repository
|