Skip to content

Conversation

@mcspr
Copy link
Collaborator

@mcspr mcspr commented Aug 29, 2025

Currently, it is mixed. Some methods allow it, some fall back to newlib or ROM funcs. Some converted c-string to String(). Or, some caused implicit conversion nuance (like String(const char*) and operator=(const char*))

Instead, try to pass data through as c-string + its length and minimize String() conversions. This also drops most of the __FlashStringHelper overloads in favour of forcibly casting it to c-string.
Internals also check for flash/non-flash to select an appropriate copy func from newlib or rom (...or one internal memcmp that is case-insensitive). Methods previously missing length argument now try to utilize it internally and thus use string.h mem* funcs instead of str*

Also refactored some long standing weirdness w/ null-checks of source strings & buffer()s

resolve #9269

@gorlov-ai would you mind checking whether this fixes your code that crashed?
(preferably clone this whole tree, but c/p just the WString{.h,.cpp} files may also work)

mcspr added 16 commits October 28, 2025 16:31
allow *all* cstr method to use flash memory arguments
ensure *all* cstr methods flow through same paths, avoid implicit String(cstr)
throw out flashstringhelper method implementations in favour of cstr
consistent behaviour when accepting cstr input
expect empty cstr for simple methods, avoid doing it w/ length present
expect {w,}buffer to be present, things are catastrophic anyways
also, redundant wbuffer check for free()
introduce sys/ pgmspace.h, string.h and stdio.h
consistent signatures, avoid depending on newlib quirks
allow strstr & strstr_P to be the same thing
wrappers expect length, thus no need to look for '\0'

only missing piece is case-insensitive memcmp (memicmp?)
since implementation requires it, manually do the tolower() loop

update replace() w/o '\0' assumptions, always use mem ranges
drop strstr usage and reuse loop blocks

also returns actual len diff after comparison is otherwise equal
@mcspr mcspr force-pushed the string/cstr-pgmspace-funcs branch from 979f9c0 to 48f9fef Compare October 28, 2025 13:32
mcspr added 3 commits October 28, 2025 16:36
incorrectly using lastIndexOf, when should be using deduced search func

since there is no reverse indexOf nor lastIndexOf allows end boundary,
adjust buffer end pointer manually by swapping it w/ the found one

plus, reinit read ptr after possibly changing buffer() location
similar to replace() use, we already know there is nothing past
previously found needle ptr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

In WString.cpp some of the methods access the insecure version of strcmp and strcnmp

1 participant