public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/66213] New: unsigned char value range can be greater than sizeof unsigned char
@ 2015-05-20 10:39 z.hegedus@t-systems.com
  2015-05-20 10:52 ` [Bug c/66213] " mpolacek at gcc dot gnu.org
  2015-05-20 11:23 ` z.hegedus@t-systems.com
  0 siblings, 2 replies; 3+ messages in thread
From: z.hegedus@t-systems.com @ 2015-05-20 10:39 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66213

            Bug ID: 66213
           Summary: unsigned char value range can be greater than sizeof
                    unsigned char
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: z.hegedus@t-systems.com
  Target Milestone: ---

Unsigned char can be greater than 1 byte (== sizeof(unsigned char))
Example:
#include <stdio.h>
int main() {
    unsigned char a=200, b=80;
    int z = a+b;
    printf("z=: %d\n", z);

        return 0;
}

When data type char or signed char is used in the example above a char overflow
occurs (as expected) but if unsigned char is used the return value can be
greater than 1 byte (or sizeof(unsigned char))

Reason:
Breakpoint 8, 0x004011f6 in main () at char.c:8
(gdb) i r
eax            0x50     80
edx            0xc8     200

Breakpoint 10, 0x00401215 in main () at char.c:10
0x0040121a      10              z = c+d;
(gdb) ni
(gdb) i r
eax            0x50     80
edx            0xffffffc8       -56

Where "c" and "d" are signed chars.

When unsigned char is used gcc uses movzx instead of movsx and probably the
sign bit is overwritten.


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

* [Bug c/66213] unsigned char value range can be greater than sizeof unsigned char
  2015-05-20 10:39 [Bug c/66213] New: unsigned char value range can be greater than sizeof unsigned char z.hegedus@t-systems.com
@ 2015-05-20 10:52 ` mpolacek at gcc dot gnu.org
  2015-05-20 11:23 ` z.hegedus@t-systems.com
  1 sibling, 0 replies; 3+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2015-05-20 10:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66213

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |mpolacek at gcc dot gnu.org
         Resolution|---                         |INVALID

--- Comment #1 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
I don't know where you think is a bug.  The usual arithmetic conversion are
performed on that addition so it is done on ints.


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

* [Bug c/66213] unsigned char value range can be greater than sizeof unsigned char
  2015-05-20 10:39 [Bug c/66213] New: unsigned char value range can be greater than sizeof unsigned char z.hegedus@t-systems.com
  2015-05-20 10:52 ` [Bug c/66213] " mpolacek at gcc dot gnu.org
@ 2015-05-20 11:23 ` z.hegedus@t-systems.com
  1 sibling, 0 replies; 3+ messages in thread
From: z.hegedus@t-systems.com @ 2015-05-20 11:23 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66213

--- Comment #2 from zh__ <z.hegedus@t-systems.com> ---
Yep, sorry. My bad.


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

end of thread, other threads:[~2015-05-20 11:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-20 10:39 [Bug c/66213] New: unsigned char value range can be greater than sizeof unsigned char z.hegedus@t-systems.com
2015-05-20 10:52 ` [Bug c/66213] " mpolacek at gcc dot gnu.org
2015-05-20 11:23 ` z.hegedus@t-systems.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).