|
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
modified 21-Aug-24 23:38pm.
|
|
|
|
|
I utilize the subscript operator w/ extreme caution. Only if the size is confirmed and the index checked against it do I utilize it.
|
|
|
|
|
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
|
|
|
|
|
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.
|
|
|
|
|
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
|
|
|
|
|
May I inquire means by which garbage value originated.
|
|
|
|
|
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
|
|
|
|
|
Don't static analyzers catch that sort of thing.
|
|
|
|
|
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
|
|
|
|
|
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;
|
|
|
|
|
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
|
|
|
|
|
I hear that!
"A little time, a little trouble, your better day"
Badfinger
|
|
|
|
|
honey the codewitch wrote: ridiculously high Are you sayin' uninitialized?
"If we don't change direction, we'll end up where we're going"
|
|
|
|
|
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
|
|
|
|
|
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"
|
|
|
|
|
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
|
|
|
|
|
Yes, it's Zig. Forgive me because I'm becoming a wordle post.
But, I just gotta say, this is how extremely easy it is to use C code in Zig...
const c = @cImport({
@cInclude("unistd.h");
});
pub fn main() void {
const res = c.write(2, "Hello C from Zig!", 17);
}
Jeremy Falcon
|
|
|
|
|
You almost got me ready to learn it.
When it will run on ARM, I will definitely consider.
A home without books is a body without soul. Marcus Tullius Cicero
PartsBin an Electronics Part Organizer - Release Version 1.4.0 (Many new features) JaxCoder.com
Latest Article: EventAggregator
|
|
|
|
|
Mike Hankey wrote: You almost got me ready to learn it. You're in luck, it already supports ARM cross compilation. Zig cross compilation I haven't tried it for ARM yet, but that's what the site says.
The main reason I'm learning it, is it's meant to be a direct successor to C... not C++ but C. You have projects like D or even Rust that creep into the overly complicated theory territory. Zig is like, nah screw that, this be C 2.0.
Don't get me wrong, you can kinda mimic interfaces in Zig as an example, but it just feels way more like C than most other languages out there. But, with some newer features that came about since the 70s... like a standard package manager that every other language besides C has standardized by now and built in unit testing. Which IMO is awesome.
It's still a young language (only started 8 years ago), but they recently got 21 million in funding for their series B. So, it's gonna continue to mature and evolve. Probably take several years to finally get to 1.0 though, so just be aware. The current release version is 0.13.0 and it'll be a bit before 0.14.0 is out. But, still... gotta start somewhere.
Jeremy Falcon
modified 21-Aug-24 21:34pm.
|
|
|
|
|
Damn another project.
A home without books is a body without soul. Marcus Tullius Cicero
PartsBin an Electronics Part Organizer - Release Version 1.4.0 (Many new features) JaxCoder.com
Latest Article: EventAggregator
|
|
|
|
|
Oh, I should say there aren't any beginner books on it yet. It's all still so new. There are some scam books that are AI generated and wrong on Amazon, but not legit ones. One is being worked on though, and I'm sure others will arrive in the future.
So, for right now, it's gonna be online resources like ziglings, ziglang.org, zig.guide, reddit, Google, etc.
Here's a list of projects using Zig, including editor plugins, etc. Zig Learning Guide & Project Lists
Reminds me of getting in on Linux during the early days though. Kinda exciting.
Jeremy Falcon
|
|
|
|
|
Sooo... it really just wants to be C when it grows up?
|
|
|
|
|
I mean I know this is a joke... so the obligatory har har har... har har har.
Buuutttt, and I know I'm sounding like a fanboi, but it's doing things that apparently the peeps behind C are too old to care about. Like, I mean, Zig sounds silly in name but I'm sure C is ran by grandpas still using an outhouse.
Let me just give you a simple example here, every other modern language has a concept of lambda type expressions (using C# nomenclature), but not C. Now, Zig doesn't do that 1 for 1, but let me just show you with code.
for (0..10) |i| {
}
Of course you can do that in C by manually declaring crap, but it's so much more verbose and a waste of typing.
Or what about a while block that supports a counter.
while (n <= 20) : (n += 1) {
}
Or and this is where things get crazy, being able to name blocks and break out of them.
namedBlock: {
break :namedBlock 42;
}
I could go on, but I'd be writing a book here. But stuff like comptime makes C macros look like a joke. I say this as a dude who loves C. I'm not a hater; I'm just a realist.
I mean like it or not man, history has shown us that things die out if they don't evolve. Nobody is speaking much Latin these days despite the fact it used to dominate the world. We're just too close to C to realize it's gotten very little love for a long time. Been 50 years man. That's half a century. The world has moved on.
Jeremy Falcon
|
|
|
|
|
"the peeps behind C are too old to care about"
sigh... that's racist. lol. Not really, but I'm trying to fix something that works in the real world. I already have some thoughts about your posts.
Charlie Gilley
“They who can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety.” BF, 1759
Has never been more appropriate.
|
|
|
|
|
charlieg wrote: sigh... that's racist. lol Touché, buddy.
Jeremy Falcon
|
|
|
|