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

@@ -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]))

View File

@@ -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;