Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Cyborg)
  • No Skin
Collapse
Brand Logo

CIRCLE WITH A DOT

  1. Home
  2. Uncategorized
  3. reposting for the day crowd: I ran into a memcmp implementation that only compared 25% of the bytes, and the issue wasn't caught in the build because the vendor toolchain failed to emit a warning.

reposting for the day crowd: I ran into a memcmp implementation that only compared 25% of the bytes, and the issue wasn't caught in the build because the vendor toolchain failed to emit a warning.

Scheduled Pinned Locked Moved Uncategorized
24 Posts 7 Posters 0 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • gsuberland@chaos.socialG gsuberland@chaos.social

    reposting for the day crowd: I ran into a memcmp implementation that only compared 25% of the bytes, and the issue wasn't caught in the build because the vendor toolchain failed to emit a warning.

    Watch out for missed warnings on vendor C++ toolchains - Graham Sutherland's Blog

    favicon

    (blog.poly.nomial.co.uk)

    gsuberland@chaos.socialG This user is from outside of this forum
    gsuberland@chaos.socialG This user is from outside of this forum
    gsuberland@chaos.social
    wrote last edited by
    #3

    to be fair it should also have been unit tested but I'm gonna cut the devs some slack here because the toolchain vendor rugpulling a whole warning category is a significantly worse offense.

    waha_06x36@mastodon.socialW 1 Reply Last reply
    0
    • gsuberland@chaos.socialG gsuberland@chaos.social

      reposting for the day crowd: I ran into a memcmp implementation that only compared 25% of the bytes, and the issue wasn't caught in the build because the vendor toolchain failed to emit a warning.

      Watch out for missed warnings on vendor C++ toolchains - Graham Sutherland's Blog

      favicon

      (blog.poly.nomial.co.uk)

      uecker@mastodon.socialU This user is from outside of this forum
      uecker@mastodon.socialU This user is from outside of this forum
      uecker@mastodon.social
      wrote last edited by
      #4

      @gsuberland Do you get a warning with GCC? If I am not mistaken, this is not catched by GCC nor clang with the warning flags shown. You need -Wconversion.

      uecker@mastodon.socialU gsuberland@chaos.socialG 2 Replies Last reply
      0
      • uecker@mastodon.socialU uecker@mastodon.social

        @gsuberland Do you get a warning with GCC? If I am not mistaken, this is not catched by GCC nor clang with the warning flags shown. You need -Wconversion.

        uecker@mastodon.socialU This user is from outside of this forum
        uecker@mastodon.socialU This user is from outside of this forum
        uecker@mastodon.social
        wrote last edited by
        #5

        @gsuberland But the other huge problem are the strict aliasing violations.

        1 Reply Last reply
        0
        • uecker@mastodon.socialU uecker@mastodon.social

          @gsuberland Do you get a warning with GCC? If I am not mistaken, this is not catched by GCC nor clang with the warning flags shown. You need -Wconversion.

          gsuberland@chaos.socialG This user is from outside of this forum
          gsuberland@chaos.socialG This user is from outside of this forum
          gsuberland@chaos.social
          wrote last edited by
          #6

          @uecker I might've bungled the flags in the post, 'cos I was tired, but the actual flags they were using in the build did generate the warning in gcc.

          I would expect -Wnarrowing to catch implicit narrowing conversions, though.

          uecker@mastodon.socialU gsuberland@chaos.socialG 2 Replies Last reply
          0
          • gsuberland@chaos.socialG gsuberland@chaos.social

            @uecker I might've bungled the flags in the post, 'cos I was tired, but the actual flags they were using in the build did generate the warning in gcc.

            I would expect -Wnarrowing to catch implicit narrowing conversions, though.

            uecker@mastodon.socialU This user is from outside of this forum
            uecker@mastodon.socialU This user is from outside of this forum
            uecker@mastodon.social
            wrote last edited by
            #7

            @gsuberland It is a narrowing conversion, but it seems C++ only disallows this in initializer lists and this is when compiler warn:
            https://eel.is/c++draft/dcl.init.list#def:conversion,narrowing

            doomed_daniel@mastodon.gamedev.placeD 1 Reply Last reply
            0
            • gsuberland@chaos.socialG gsuberland@chaos.social

              @uecker I might've bungled the flags in the post, 'cos I was tired, but the actual flags they were using in the build did generate the warning in gcc.

              I would expect -Wnarrowing to catch implicit narrowing conversions, though.

              gsuberland@chaos.socialG This user is from outside of this forum
              gsuberland@chaos.socialG This user is from outside of this forum
              gsuberland@chaos.social
              wrote last edited by
              #8

              @uecker if -Wnarrowing doesn't catch narrowing conversions then I will edit the post to say "also gcc is terrible at naming things and encourages bugs as a result"

              uecker@mastodon.socialU 1 Reply Last reply
              0
              • uecker@mastodon.socialU uecker@mastodon.social

                @gsuberland It is a narrowing conversion, but it seems C++ only disallows this in initializer lists and this is when compiler warn:
                https://eel.is/c++draft/dcl.init.list#def:conversion,narrowing

                doomed_daniel@mastodon.gamedev.placeD This user is from outside of this forum
                doomed_daniel@mastodon.gamedev.placeD This user is from outside of this forum
                doomed_daniel@mastodon.gamedev.place
                wrote last edited by
                #9

                @uecker @gsuberland
                shouldn't things that are disallowed be errors, while things that are allowed but probably a bad idea warnings?

                uecker@mastodon.socialU 1 Reply Last reply
                0
                • gsuberland@chaos.socialG gsuberland@chaos.social

                  @uecker if -Wnarrowing doesn't catch narrowing conversions then I will edit the post to say "also gcc is terrible at naming things and encourages bugs as a result"

                  uecker@mastodon.socialU This user is from outside of this forum
                  uecker@mastodon.socialU This user is from outside of this forum
                  uecker@mastodon.social
                  wrote last edited by
                  #10

                  @gsuberland Fair. You should add clang as well... and please add that you need to use -Wconversion

                  rjmccall@hachyderm.ioR 1 Reply Last reply
                  0
                  • doomed_daniel@mastodon.gamedev.placeD doomed_daniel@mastodon.gamedev.place

                    @uecker @gsuberland
                    shouldn't things that are disallowed be errors, while things that are allowed but probably a bad idea warnings?

                    uecker@mastodon.socialU This user is from outside of this forum
                    uecker@mastodon.socialU This user is from outside of this forum
                    uecker@mastodon.social
                    wrote last edited by
                    #11

                    @Doomed_Daniel @gsuberland Obviously. The problem is there are too many people with broken code that do not want to fix it. For example, implicit int in C was disallowed in C99, GCC made it a hard error in 2024 (GCC 14) - 25 years later.

                    1 Reply Last reply
                    0
                    • gsuberland@chaos.socialG gsuberland@chaos.social

                      to be fair it should also have been unit tested but I'm gonna cut the devs some slack here because the toolchain vendor rugpulling a whole warning category is a significantly worse offense.

                      waha_06x36@mastodon.socialW This user is from outside of this forum
                      waha_06x36@mastodon.socialW This user is from outside of this forum
                      waha_06x36@mastodon.social
                      wrote last edited by
                      #12

                      @gsuberland Pretty sure this would have passed the unit tests that anyone would have been likely to write anyway.

                      gsuberland@chaos.socialG 1 Reply Last reply
                      0
                      • waha_06x36@mastodon.socialW waha_06x36@mastodon.social

                        @gsuberland Pretty sure this would have passed the unit tests that anyone would have been likely to write anyway.

                        gsuberland@chaos.socialG This user is from outside of this forum
                        gsuberland@chaos.socialG This user is from outside of this forum
                        gsuberland@chaos.social
                        wrote last edited by
                        #13

                        @WAHa_06x36 this is why fuzz testing is a thing!

                        waha_06x36@mastodon.socialW 1 Reply Last reply
                        0
                        • gsuberland@chaos.socialG gsuberland@chaos.social

                          @WAHa_06x36 this is why fuzz testing is a thing!

                          waha_06x36@mastodon.socialW This user is from outside of this forum
                          waha_06x36@mastodon.socialW This user is from outside of this forum
                          waha_06x36@mastodon.social
                          wrote last edited by
                          #14

                          @gsuberland Hmm, would even fuzz testing find it? That seems tricky to set up in a way that a) would actually find the bug and b) would occur to you before seeing the bug.

                          I guess for very short inputs you might find it more easily by chance...

                          gsuberland@chaos.socialG halcy@icosahedron.websiteH 2 Replies Last reply
                          0
                          • waha_06x36@mastodon.socialW waha_06x36@mastodon.social

                            @gsuberland Hmm, would even fuzz testing find it? That seems tricky to set up in a way that a) would actually find the bug and b) would occur to you before seeing the bug.

                            I guess for very short inputs you might find it more easily by chance...

                            gsuberland@chaos.socialG This user is from outside of this forum
                            gsuberland@chaos.socialG This user is from outside of this forum
                            gsuberland@chaos.social
                            wrote last edited by
                            #15

                            @WAHa_06x36 of course. fuzz testing would quickly find memcmp("aaaa", "Aaaa") == 0 or memcmp("aaaa", "aaaA") == 0 as a violation of the contract (depending on endianness)

                            waha_06x36@mastodon.socialW 1 Reply Last reply
                            0
                            • waha_06x36@mastodon.socialW waha_06x36@mastodon.social

                              @gsuberland Hmm, would even fuzz testing find it? That seems tricky to set up in a way that a) would actually find the bug and b) would occur to you before seeing the bug.

                              I guess for very short inputs you might find it more easily by chance...

                              halcy@icosahedron.websiteH This user is from outside of this forum
                              halcy@icosahedron.websiteH This user is from outside of this forum
                              halcy@icosahedron.website
                              wrote last edited by
                              #16

                              @WAHa_06x36 @gsuberland i think „only one byte differs“ kind of tests would probably find it, right? And these seem like something you’d write to test that

                              1 Reply Last reply
                              0
                              • uecker@mastodon.socialU uecker@mastodon.social

                                @gsuberland Fair. You should add clang as well... and please add that you need to use -Wconversion

                                rjmccall@hachyderm.ioR This user is from outside of this forum
                                rjmccall@hachyderm.ioR This user is from outside of this forum
                                rjmccall@hachyderm.io
                                wrote last edited by
                                #17

                                @gsuberland @uecker I won’t defend Clang’s naming choices in every case, but I believe this specific one is all GCC; Clang originally called this -Wc++0x-narrowing (eventually -Wc++11-narrowing) and only added the -Wnarrowing alias for GCC compatibility. In any case, the documentation should really suggest -Wconversion, and on that front I can definitely accept blame for Clang, because our warning group documentation is awful

                                gsuberland@chaos.socialG 1 Reply Last reply
                                0
                                • rjmccall@hachyderm.ioR rjmccall@hachyderm.io

                                  @gsuberland @uecker I won’t defend Clang’s naming choices in every case, but I believe this specific one is all GCC; Clang originally called this -Wc++0x-narrowing (eventually -Wc++11-narrowing) and only added the -Wnarrowing alias for GCC compatibility. In any case, the documentation should really suggest -Wconversion, and on that front I can definitely accept blame for Clang, because our warning group documentation is awful

                                  gsuberland@chaos.socialG This user is from outside of this forum
                                  gsuberland@chaos.socialG This user is from outside of this forum
                                  gsuberland@chaos.social
                                  wrote last edited by
                                  #18

                                  @rjmccall @uecker gcc's docs don't even have a paragraph explaining what Wnarrowing does, as far as I can see.

                                  uecker@mastodon.socialU 1 Reply Last reply
                                  0
                                  • gsuberland@chaos.socialG gsuberland@chaos.social

                                    @rjmccall @uecker gcc's docs don't even have a paragraph explaining what Wnarrowing does, as far as I can see.

                                    uecker@mastodon.socialU This user is from outside of this forum
                                    uecker@mastodon.socialU This user is from outside of this forum
                                    uecker@mastodon.social
                                    wrote last edited by
                                    #19

                                    @gsuberland @rjmccall It seems it is under the language dialects options and explanation is not really clear. https://gcc.gnu.org/onlinedocs/gcc-15.2.0/gcc/C_002b_002b-Dialect-Options.html

                                    gsuberland@chaos.socialG 1 Reply Last reply
                                    0
                                    • uecker@mastodon.socialU uecker@mastodon.social

                                      @gsuberland @rjmccall It seems it is under the language dialects options and explanation is not really clear. https://gcc.gnu.org/onlinedocs/gcc-15.2.0/gcc/C_002b_002b-Dialect-Options.html

                                      gsuberland@chaos.socialG This user is from outside of this forum
                                      gsuberland@chaos.socialG This user is from outside of this forum
                                      gsuberland@chaos.social
                                      wrote last edited by
                                      #20

                                      @uecker @rjmccall I'll update the blog post later tonight if I get time. annoyingly today is extremely busy >_<

                                      1 Reply Last reply
                                      0
                                      • gsuberland@chaos.socialG gsuberland@chaos.social

                                        @WAHa_06x36 of course. fuzz testing would quickly find memcmp("aaaa", "Aaaa") == 0 or memcmp("aaaa", "aaaA") == 0 as a violation of the contract (depending on endianness)

                                        waha_06x36@mastodon.socialW This user is from outside of this forum
                                        waha_06x36@mastodon.socialW This user is from outside of this forum
                                        waha_06x36@mastodon.social
                                        wrote last edited by
                                        #21

                                        @gsuberland I mean, if you set up a special test harness against a known-good implementation and used something like afl that actually instruments the code itself, maybe, but, who would ever do that?

                                        gsuberland@chaos.socialG 1 Reply Last reply
                                        0
                                        • waha_06x36@mastodon.socialW waha_06x36@mastodon.social

                                          @gsuberland I mean, if you set up a special test harness against a known-good implementation and used something like afl that actually instruments the code itself, maybe, but, who would ever do that?

                                          gsuberland@chaos.socialG This user is from outside of this forum
                                          gsuberland@chaos.socialG This user is from outside of this forum
                                          gsuberland@chaos.social
                                          wrote last edited by
                                          #22

                                          @WAHa_06x36 quite a few people! there are even coverage tools specifically for doing this.

                                          waha_06x36@mastodon.socialW 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups