From 5ca3b2605cc9ab5b33032c6478147366be60cd95 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Thu, 24 May 2018 21:52:54 -0600 Subject: [PATCH] Use gdb::byte_vector in remote.c This changes a couple of spots in remote.c to use gdb::byte_vector, allowing for some cleanup removal. ChangeLog 2018-05-25 Tom Tromey * remote.c (remote_target::remote_file_get): Use gdb::byte_vector. (remote_target::remote_file_put): Likewise. --- gdb/ChangeLog | 6 ++++++ gdb/remote.c | 22 +++++++--------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index dd01ce376c8..b697326e56a 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,9 @@ +2018-05-25 Tom Tromey + + * remote.c (remote_target::remote_file_get): Use + gdb::byte_vector. + (remote_target::remote_file_put): Likewise. + 2018-05-25 Tom Tromey * coff-pe-read.c (struct read_pe_section_data) : Now diff --git a/gdb/remote.c b/gdb/remote.c index 38ba7b581cd..e7ade41c340 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -12599,9 +12599,7 @@ void remote_target::remote_file_put (const char *local_file, const char *remote_file, int from_tty) { - struct cleanup *back_to; int retcode, remote_errno, bytes, io_size; - gdb_byte *buffer; int bytes_in_buffer; int saw_eof; ULONGEST offset; @@ -12621,8 +12619,7 @@ remote_target::remote_file_put (const char *local_file, const char *remote_file, /* Send up to this many bytes at once. They won't all fit in the remote packet limit, so we'll transfer slightly fewer. */ io_size = get_remote_packet_size (); - buffer = (gdb_byte *) xmalloc (io_size); - back_to = make_cleanup (xfree, buffer); + gdb::byte_vector buffer (io_size); bytes_in_buffer = 0; saw_eof = 0; @@ -12631,7 +12628,7 @@ remote_target::remote_file_put (const char *local_file, const char *remote_file, { if (!saw_eof) { - bytes = fread (buffer + bytes_in_buffer, 1, + bytes = fread (buffer.data () + bytes_in_buffer, 1, io_size - bytes_in_buffer, file.get ()); if (bytes == 0) @@ -12654,7 +12651,7 @@ remote_target::remote_file_put (const char *local_file, const char *remote_file, bytes += bytes_in_buffer; bytes_in_buffer = 0; - retcode = remote_hostio_pwrite (fd.get (), buffer, bytes, + retcode = remote_hostio_pwrite (fd.get (), buffer.data (), bytes, offset, &remote_errno); if (retcode < 0) @@ -12666,7 +12663,7 @@ remote_target::remote_file_put (const char *local_file, const char *remote_file, /* Short write. Save the rest of the read data for the next write. */ bytes_in_buffer = bytes - retcode; - memmove (buffer, buffer + retcode, bytes_in_buffer); + memmove (buffer.data (), buffer.data () + retcode, bytes_in_buffer); } offset += retcode; @@ -12677,7 +12674,6 @@ remote_target::remote_file_put (const char *local_file, const char *remote_file, if (from_tty) printf_filtered (_("Successfully sent file \"%s\".\n"), local_file); - do_cleanups (back_to); } void @@ -12695,9 +12691,7 @@ void remote_target::remote_file_get (const char *remote_file, const char *local_file, int from_tty) { - struct cleanup *back_to; int remote_errno, bytes, io_size; - gdb_byte *buffer; ULONGEST offset; scoped_remote_fd fd @@ -12714,13 +12708,12 @@ remote_target::remote_file_get (const char *remote_file, const char *local_file, /* Send up to this many bytes at once. They won't all fit in the remote packet limit, so we'll transfer slightly fewer. */ io_size = get_remote_packet_size (); - buffer = (gdb_byte *) xmalloc (io_size); - back_to = make_cleanup (xfree, buffer); + gdb::byte_vector buffer (io_size); offset = 0; while (1) { - bytes = remote_hostio_pread (fd.get (), buffer, io_size, offset, + bytes = remote_hostio_pread (fd.get (), buffer.data (), io_size, offset, &remote_errno); if (bytes == 0) /* Success, but no bytes, means end-of-file. */ @@ -12730,7 +12723,7 @@ remote_target::remote_file_get (const char *remote_file, const char *local_file, offset += bytes; - bytes = fwrite (buffer, 1, bytes, file.get ()); + bytes = fwrite (buffer.data (), 1, bytes, file.get ()); if (bytes == 0) perror_with_name (local_file); } @@ -12740,7 +12733,6 @@ remote_target::remote_file_get (const char *remote_file, const char *local_file, if (from_tty) printf_filtered (_("Successfully fetched file \"%s\".\n"), remote_file); - do_cleanups (back_to); } void -- 2.30.2