Re: [RFC-v5] Fix .text section offset for windows DLL (was Calling __stdcall functions in the inferior)

Pedro Alves
2012-12-13T15:03:40Z

On 12/13/2012 02:56 PM, Pierre Muller wrote:

> Maybe removing the memset before and replacing it by a
> sec_name[SCNNMLEN] = '\0';
> after the call to bfd_bread
> would make it even more clear that you
> always get a nicely zero terminated string...

That works too. I'm applying this then.

2012-12-13 Pedro Alves <palves@redhat.com>

* coff-pe-read.c: Include coff/internal.h.
(read_pe_exported_syms): Use SCNNMLEN instead of hardcoded 8.
Null terminate buffer explicitly instead of memset the whole
buffer.

---

gdb/coff-pe-read.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/gdb/coff-pe-read.c b/gdb/coff-pe-read.c
index 10bba78..9ebff12 100644
--- a/gdb/coff-pe-read.c
+++ b/gdb/coff-pe-read.c
@@ -34,6 +34,7 @@
#include "symfile.h"
#include "objfiles.h"
#include "common/common-utils.h"
+#include "coff/internal.h"

#include <ctype.h>

@@ -464,12 +465,12 @@ read_pe_exported_syms (struct objfile *objfile)
unsigned long vsize = pe_get32 (dll, secptr1 + 8);
unsigned long vaddr = pe_get32 (dll, secptr1 + 12);
unsigned long characteristics = pe_get32 (dll, secptr1 + 36);
- char sec_name[9];
+ char sec_name[SCNNMLEN + 1];
int sectix;

- memset (sec_name, 0, sizeof (sec_name));
bfd_seek (dll, (file_ptr) secptr1 + 0, SEEK_SET);
- bfd_bread (sec_name, (bfd_size_type) 8, dll);
+ bfd_bread (sec_name, (bfd_size_type) SCNNMLEN, dll);
+ sec_name[SCNNMLEN] = '\0';

sectix = read_pe_section_index (sec_name);