Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • 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 (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Shooting yourself in the foot, vs blowing your whole damned leg off.

Shooting yourself in the foot, vs blowing your whole damned leg off.

Scheduled Pinned Locked Moved The Lounge
designc++visual-studiocomgraphics
16 Posts 5 Posters 2 Views 1 Watching
  • 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.
  • honey the codewitchH Offline
    honey the codewitchH Offline
    honey the codewitch
    wrote on last edited by
    #1

    Edit: Actual photographic evidence of victory non-trivial SVG document[^]

    parse_res.attr[0].strokeDashCount = 0;

    It has taken me a day of extremely stressful hair pulling to find that this line of code didn't exist and it should have. It was manifesting as a stack overflow, so I spent my day, tracking that, and pruning the stack. Here was the offending code that caused the memory corruption that reported as a stack issue.

    for (i = 0; i < attr->strokeDashCount; i++)
    shape->stroke_dash_array[i] = attr->strokeDashArray[i] * scale;

    Here the strokeDashCount value was a ridiculously high garbage number, with (un)predictable results. This never would have happened in a high level language. I love me some C and C++. It's an incredible programming language family, but also a very powerful weapon you can wield against yourself if you're not careful.

    Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

    B J M 4 Replies Last reply
    0
    • honey the codewitchH honey the codewitch

      Edit: Actual photographic evidence of victory non-trivial SVG document[^]

      parse_res.attr[0].strokeDashCount = 0;

      It has taken me a day of extremely stressful hair pulling to find that this line of code didn't exist and it should have. It was manifesting as a stack overflow, so I spent my day, tracking that, and pruning the stack. Here was the offending code that caused the memory corruption that reported as a stack issue.

      for (i = 0; i < attr->strokeDashCount; i++)
      shape->stroke_dash_array[i] = attr->strokeDashArray[i] * scale;

      Here the strokeDashCount value was a ridiculously high garbage number, with (un)predictable results. This never would have happened in a high level language. I love me some C and C++. It's an incredible programming language family, but also a very powerful weapon you can wield against yourself if you're not careful.

      Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

      B Offline
      B Offline
      BernardIE5317
      wrote on last edited by
      #2

      I utilize the subscript operator w/ extreme caution. Only if the size is confirmed and the index checked against it do I utilize it.

      honey the codewitchH 1 Reply Last reply
      0
      • honey the codewitchH honey the codewitch

        Edit: Actual photographic evidence of victory non-trivial SVG document[^]

        parse_res.attr[0].strokeDashCount = 0;

        It has taken me a day of extremely stressful hair pulling to find that this line of code didn't exist and it should have. It was manifesting as a stack overflow, so I spent my day, tracking that, and pruning the stack. Here was the offending code that caused the memory corruption that reported as a stack issue.

        for (i = 0; i < attr->strokeDashCount; i++)
        shape->stroke_dash_array[i] = attr->strokeDashArray[i] * scale;

        Here the strokeDashCount value was a ridiculously high garbage number, with (un)predictable results. This never would have happened in a high level language. I love me some C and C++. It's an incredible programming language family, but also a very powerful weapon you can wield against yourself if you're not careful.

        Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

        B Offline
        B Offline
        BernardIE5317
        wrote on last edited by
        #3

        Am a bit surprised you did not utilize an assert to verify the size of the indexed object is in fact the presumed quantity as stored in variable.

        honey the codewitchH 1 Reply Last reply
        0
        • honey the codewitchH honey the codewitch

          Edit: Actual photographic evidence of victory non-trivial SVG document[^]

          parse_res.attr[0].strokeDashCount = 0;

          It has taken me a day of extremely stressful hair pulling to find that this line of code didn't exist and it should have. It was manifesting as a stack overflow, so I spent my day, tracking that, and pruning the stack. Here was the offending code that caused the memory corruption that reported as a stack issue.

          for (i = 0; i < attr->strokeDashCount; i++)
          shape->stroke_dash_array[i] = attr->strokeDashArray[i] * scale;

          Here the strokeDashCount value was a ridiculously high garbage number, with (un)predictable results. This never would have happened in a high level language. I love me some C and C++. It's an incredible programming language family, but also a very powerful weapon you can wield against yourself if you're not careful.

          Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

          J Offline
          J Offline
          jmaida
          wrote on last edited by
          #4

          I hear that!

          "A little time, a little trouble, your better day" Badfinger

          1 Reply Last reply
          0
          • B BernardIE5317

            Am a bit surprised you did not utilize an assert to verify the size of the indexed object is in fact the presumed quantity as stored in variable.

            honey the codewitchH Offline
            honey the codewitchH Offline
            honey the codewitch
            wrote on last edited by
            #5

            I don't like using assert() because it simply causes a bootloop on these devices when hit. I don't have a debugger. Also this code did not originate with me. I forked it from another project, and have done a lot of work to it, but a significant portion I have yet to touch.

            Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

            B 1 Reply Last reply
            0
            • B BernardIE5317

              I utilize the subscript operator w/ extreme caution. Only if the size is confirmed and the index checked against it do I utilize it.

              honey the codewitchH Offline
              honey the codewitchH Offline
              honey the codewitch
              wrote on last edited by
              #6

              It was checked. But the number it was checked against was garbage.

              Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

              1 Reply Last reply
              0
              • honey the codewitchH honey the codewitch

                I don't like using assert() because it simply causes a bootloop on these devices when hit. I don't have a debugger. Also this code did not originate with me. I forked it from another project, and have done a lot of work to it, but a significant portion I have yet to touch.

                Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                B Offline
                B Offline
                BernardIE5317
                wrote on last edited by
                #7

                May I inquire means by which garbage value originated.

                honey the codewitchH 1 Reply Last reply
                0
                • B BernardIE5317

                  May I inquire means by which garbage value originated.

                  honey the codewitchH Offline
                  honey the codewitchH Offline
                  honey the codewitch
                  wrote on last edited by
                  #8

                  solar flares probably. It's what happens in C and C++ when you don't initialize a value explicitly on a release build. It's garbage. leftover bits in stale ram.

                  Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                  B 1 Reply Last reply
                  0
                  • honey the codewitchH honey the codewitch

                    solar flares probably. It's what happens in C and C++ when you don't initialize a value explicitly on a release build. It's garbage. leftover bits in stale ram.

                    Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                    B Offline
                    B Offline
                    BernardIE5317
                    wrote on last edited by
                    #9

                    Don't static analyzers catch that sort of thing.

                    honey the codewitchH 1 Reply Last reply
                    0
                    • B BernardIE5317

                      Don't static analyzers catch that sort of thing.

                      honey the codewitchH Offline
                      honey the codewitchH Offline
                      honey the codewitch
                      wrote on last edited by
                      #10

                      It's not easy to run static analysis on this code because I don't have much control over my build environment. It's all controlled and automagic via PlatformIO. That's often nice because it streamlines my workflow but limits the sorts of tools i can use.

                      Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                      G 1 Reply Last reply
                      0
                      • honey the codewitchH honey the codewitch

                        It's not easy to run static analysis on this code because I don't have much control over my build environment. It's all controlled and automagic via PlatformIO. That's often nice because it streamlines my workflow but limits the sorts of tools i can use.

                        Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                        G Offline
                        G Offline
                        Gary R Wheeler
                        wrote on last edited by
                        #11

                        Hmm. Just a suggestion, but I've used static analyzers such as those included in VS2022 against code from embedded environments more than once. True, it can be a PITA to set up and you have to separate the wheat from the chaff. The end result however can catch a lot of simple errors that aren't detectable by less comprehensive compilers.

                        Software Zen: delete this;

                        honey the codewitchH 1 Reply Last reply
                        0
                        • honey the codewitchH honey the codewitch

                          Edit: Actual photographic evidence of victory non-trivial SVG document[^]

                          parse_res.attr[0].strokeDashCount = 0;

                          It has taken me a day of extremely stressful hair pulling to find that this line of code didn't exist and it should have. It was manifesting as a stack overflow, so I spent my day, tracking that, and pruning the stack. Here was the offending code that caused the memory corruption that reported as a stack issue.

                          for (i = 0; i < attr->strokeDashCount; i++)
                          shape->stroke_dash_array[i] = attr->strokeDashArray[i] * scale;

                          Here the strokeDashCount value was a ridiculously high garbage number, with (un)predictable results. This never would have happened in a high level language. I love me some C and C++. It's an incredible programming language family, but also a very powerful weapon you can wield against yourself if you're not careful.

                          Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                          M Offline
                          M Offline
                          megaadam
                          wrote on last edited by
                          #12

                          honey the codewitch wrote:

                          ridiculously high

                          Are you sayin' uninitialized?

                          "If we don't change direction, we'll end up where we're going"

                          honey the codewitchH 1 Reply Last reply
                          0
                          • M megaadam

                            honey the codewitch wrote:

                            ridiculously high

                            Are you sayin' uninitialized?

                            "If we don't change direction, we'll end up where we're going"

                            honey the codewitchH Offline
                            honey the codewitchH Offline
                            honey the codewitch
                            wrote on last edited by
                            #13

                            yes, which in this case resulted in a very high value. (The machine is realtime, which means the value is the same every time it boots, even though it's "garbage")

                            Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                            M 1 Reply Last reply
                            0
                            • G Gary R Wheeler

                              Hmm. Just a suggestion, but I've used static analyzers such as those included in VS2022 against code from embedded environments more than once. True, it can be a PITA to set up and you have to separate the wheat from the chaff. The end result however can catch a lot of simple errors that aren't detectable by less comprehensive compilers.

                              Software Zen: delete this;

                              honey the codewitchH Offline
                              honey the codewitchH Offline
                              honey the codewitch
                              wrote on last edited by
                              #14

                              It's far easier to keep my lib cross platform, run static analysis on what I can on the PC, and furble with the rest on embedded blindly if needed than it is to try to make PIO's toolchain work outside the PIO IDE.

                              Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                              1 Reply Last reply
                              0
                              • honey the codewitchH honey the codewitch

                                yes, which in this case resulted in a very high value. (The machine is realtime, which means the value is the same every time it boots, even though it's "garbage")

                                Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                                M Offline
                                M Offline
                                megaadam
                                wrote on last edited by
                                #15

                                Which baffled me, since it that kind of mistake sounds soo different from your usual meticulous self !

                                "If we don't change direction, we'll end up where we're going"

                                honey the codewitchH 1 Reply Last reply
                                0
                                • M megaadam

                                  Which baffled me, since it that kind of mistake sounds soo different from your usual meticulous self !

                                  "If we don't change direction, we'll end up where we're going"

                                  honey the codewitchH Offline
                                  honey the codewitchH Offline
                                  honey the codewitch
                                  wrote on last edited by
                                  #16

                                  This particular code is really complicated. Look at this mess

                                  typedef struct NSVGattrib {
                                  char id[64];
                                  float xform[6];
                                  gfx::rgba_pixel<32> fillColor;
                                  gfx::rgba_pixel<32> strokeColor;
                                  float opacity;
                                  float fillOpacity;
                                  float strokeOpacity;
                                  char fillGradient[64];
                                  char strokeGradient[64];
                                  float strokeWidth;
                                  float strokeDashOffset;
                                  float strokeDashArray[NSVG_MAX_DASHES];
                                  int strokeDashCount;
                                  svg_line_join strokeLineJoin;
                                  svg_line_cap strokeLineCap;
                                  float miterLimit;
                                  svg_fill_rule fillRule;
                                  float fontSize;
                                  gfx::rgba_pixel<32> stopColor;
                                  float stopOpacity;
                                  float stopOffset;
                                  char hasFill;
                                  char hasStroke;
                                  char visible;
                                  } NSVGattrib;
                                  using reader_t = ml_reader_ex<2048>;
                                  struct svg_css_class {
                                  char selector[512];
                                  char* value;
                                  svg_css_class* next;
                                  };
                                  struct svg_parse_result {
                                  reader_t* reader;
                                  svg_css_class* css_classes;
                                  svg_css_class* css_class_tail;
                                  void* (*allocator)(size_t);
                                  void* (*reallocator)(void*, size_t);
                                  void (*deallocator)(void*);
                                  char lname[32];
                                  char aname[512];
                                  char avalue[512];
                                  char style_val[256];
                                  char class_val[128];
                                  char* d;
                                  size_t d_size;
                                  NSVGattrib attr[NSVG_MAX_ATTR];
                                  int attrHead;
                                  float* pts;
                                  int npts;
                                  int cpts;
                                  svg_path* plist;
                                  size_t image_size;
                                  svg_image_info* image;
                                  NSVGgradientData* gradients;
                                  svg_shape* shapesTail;
                                  float viewMinx, viewMiny, viewWidth, viewHeight;
                                  int alignX, alignY, alignType;
                                  float dpi;
                                  char pathFlag;
                                  char defsFlag;
                                  };

                                  I highlighted the portion of the inner structure I forgot to initialize (the head attribute, as the rest are copied from that)

                                  Check out my IoT graphics library here: https://honeythecodewitch.com/gfx And my IoT UI/User Experience library here: https://honeythecodewitch.com/uix

                                  1 Reply Last reply
                                  0
                                  Reply
                                  • Reply as topic
                                  Log in to reply
                                  • Oldest to Newest
                                  • Newest to Oldest
                                  • Most Votes


                                  • Login

                                  • Don't have an account? Register

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