-
Notifications
You must be signed in to change notification settings - Fork 138
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace string comparison functions #1482
Conversation
+ minor formatting changes
Thanks for the PR, @MCUdude. I have been meaning to replace most memory string comparisons with testing bits in a new |
That's totally fine @stefanrueger! Several other string comparisons are still done "the old way" that could be replaced. If you think you'll accept the PR once I'm finished, I can continue replacing the rest of the string comparisons in the other files as well, and deal with irregular formatting if I come across it. |
Thanks @MCUdude. Yes, the PR looks fine. I might have chosen a less permissive variant instead of `str_contains(m->desc, "fuse")` sth along the lines of
```
strlen(m->desc) <= 5 && (str_ends(m->desc, "fuse") || str_begins(m->desc, "fuse"))
```
that entertains the likes of "fuse", "fuse0" and "lfuse" but it's also OK as is. Unlikely Micochip will invent a memory `pwroffuse` or similar that contains "fuse" but isn't one.
|
Good idea! I ended up using the following code instead, that's a little more compact but still does the same thing: else if (str_contains(mem->desc, "fuse") && strlen(mem->desc) <= 5) I've updated the PR and replaced (almost) all strcmp/strncmp/strstr function calls. There are still a few left that I didn't dare to touch in case I screwed up something. |
libavrdude.h isn't included in avrintel.c/h
Well spotted! Best to leave |
Yes, some are actually needed to facilitate sorting, ie, provide an int that can be negative, postitive or zero. |
Yes, I realized that shortly after pushing the commit. Fixed!
I've tried to be as careful as I can and left strcmp/strncmp where ever non-boolean value (or a returned pointer) is needed. |
It's a complex, grown, haphazard project on its own with a lot of source files (incl avrlib, .atdf files) hand-curated errata lists in, ahem, perl that famously is one of the few languages that is easier to write than to read. |
This PR replaces the
strcmp
/strncmp
/strcasecmp
/strncmp
string comparison functions with Avrdude's ownstr_eq
/str_starts
/str_caseeq
etc.I've so far only modified
jtag3.c
,stk500v2.c
,jtagmkii.c
andjtagmki.c
, but I can go through the entire code base if that's OK. When grepping forstrcmp
orstrncmp
, I realize there aren't that many occurrences left in the codebase.I've also slightly simplified the way jtag3/jtagmkii/jtagmki/stk500v2 deals with the various fuses.