diff --git a/gdb/coffread.c b/gdb/coffread.c index 33fb2ba1fca..6ec341c61c2 100644 --- a/gdb/coffread.c +++ b/gdb/coffread.c @@ -1371,8 +1371,9 @@ coff_getfilename (union internal_auxent *aux_entry) } else { - strncpy (buffer, aux_entry->x_file.x_n.x_fname, FILNMLEN); - buffer[FILNMLEN] = '\0'; + size_t x_fname_len = sizeof (aux_entry->x_file.x_n.x_fname); + strncpy (buffer, aux_entry->x_file.x_n.x_fname, x_fname_len); + buffer[x_fname_len] = '\0'; } result = buffer; diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c index 1538d1c823d..8930cf1bc35 100644 --- a/gdb/xcoffread.c +++ b/gdb/xcoffread.c @@ -1598,8 +1598,9 @@ coff_getfilename (union internal_auxent *aux_entry, struct objfile *objfile) + aux_entry->x_file.x_n.x_n.x_offset)); else { - strncpy (buffer, aux_entry->x_file.x_n.x_fname, FILNMLEN); - buffer[FILNMLEN] = '\0'; + size_t x_fname_len = sizeof (aux_entry->x_file.x_n.x_fname); + strncpy (buffer, aux_entry->x_file.x_n.x_fname, x_fname_len); + buffer[x_fname_len] = '\0'; } return (buffer); }