public inbox for gdb-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug gdb/26842] New: Wrong repeat count for char arrays
@ 2020-11-04 20:41 bmburstein at gmail dot com
  2020-11-05 15:06 ` [Bug gdb/26842] " bmburstein at gmail dot com
  0 siblings, 1 reply; 2+ messages in thread
From: bmburstein at gmail dot com @ 2020-11-04 20:41 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=26842

            Bug ID: 26842
           Summary: Wrong repeat count for char arrays
           Product: gdb
           Version: HEAD
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: gdb
          Assignee: unassigned at sourceware dot org
          Reporter: bmburstein at gmail dot com
  Target Milestone: ---

When a char array ends with a repeated character, the repeat counter is off by
one. This doesn't happen when it is not at the end of the array, or with other
arrays.

Here is my sample program:

1       #include <stdio.h>
2       #include <string.h>
3       int main() {
4        struct {
5         int i[20];
6         char c[20];
7        } s[20];
8        memset(&s,0,sizeof(s));
9        printf("break here\n");
10       s[0].c[19] = 1;
11       printf("and here\n");
12      }


And here is my relevant (annotated) gdb session:

(gdb) b 9
Breakpoint 1 at 0x118c: file t.c, line 9.
(gdb) b 11
Breakpoint 2 at 0x119f: file t.c, line 11.
(gdb) r
Starting program: /home/baruch/a.out

Breakpoint 1, main () at t.c:9
9        printf("break here\n");
(gdb) p s
$1 = {{i = {0 <repeats 20 times>}, c = '\000' <repeats 19 times>} <repeats 20
times>}
//////////// Notice how both `i` and `s` are said to repeat 20 times, but `c`
only 19 times. ////////////
(gdb) c
Continuing.
break here

Breakpoint 2, main () at t.c:11
11       printf("and here\n");
(gdb) p s
$2 = {{i = {0 <repeats 20 times>}, c = '\000' <repeats 19 times>, "\001"}, {i =
{0 <repeats 20 times>}, c = '\000' <repeats 19 times>} <repeats 19 times>}
//////////// Notice how `c` still says it repeats 19 times, but now has another
element after the repeat ////////////


To help with this: My attempts to fix this got as far as figuring out the
problem is in the function `count_next_character` in `valprint.c`, but that is
as far as I could get.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug gdb/26842] Wrong repeat count for char arrays
  2020-11-04 20:41 [Bug gdb/26842] New: Wrong repeat count for char arrays bmburstein at gmail dot com
@ 2020-11-05 15:06 ` bmburstein at gmail dot com
  0 siblings, 0 replies; 2+ messages in thread
From: bmburstein at gmail dot com @ 2020-11-05 15:06 UTC (permalink / raw)
  To: gdb-prs

https://sourceware.org/bugzilla/show_bug.cgi?id=26842

--- Comment #1 from Baruch <bmburstein at gmail dot com> ---
I was wrong about the source of the problem. It is in the function
generic_printstr (in file valprint.c), which gets a parameter
c_style_terminator, which causes the last char to be removed if it is a '\0',
so this only happens if the character is '\0'. Still seems wrong, but I am not
sure what would be correct.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-11-05 15:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-04 20:41 [Bug gdb/26842] New: Wrong repeat count for char arrays bmburstein at gmail dot com
2020-11-05 15:06 ` [Bug gdb/26842] " bmburstein at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).