Skip to content

Fixed StringSubstring() case where the result is one character returns NULL#279

Open
craigcomstock wants to merge 2 commits into
NorthernTechHQ:masterfrom
craigcomstock:string-lib-fixes
Open

Fixed StringSubstring() case where the result is one character returns NULL#279
craigcomstock wants to merge 2 commits into
NorthernTechHQ:masterfrom
craigcomstock:string-lib-fixes

Conversation

@craigcomstock

Copy link
Copy Markdown
Contributor

Ticket: none
Changelog: none

@mender-test-bot

Copy link
Copy Markdown

There was an error running your pipeline, see logs for details.

@craigcomstock craigcomstock requested a review from larsewi June 22, 2026 16:19
Comment on lines +372 to +378
static void test_substring_result_is_one_char(void)
{
char *new_string = StringSubstring("[1]", 3, 1, -1);
assert_string_equal(new_string, "1");
free(new_string);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, but let's maybe add a few more tests to be sure? I.e. what happens when the 1 char string is at the beginning or end? What happens when the input string is also 1 character? What about when the input or the result is 0 length?

@mender-test-bot

Copy link
Copy Markdown

There was an error syncing branches, see logs for details.

@mender-test-bot

Copy link
Copy Markdown

There was an error running your pipeline, see logs for details.

…eturned

Test cases added.

Ticket: none
Changelog: none
…g for non-portable VLA usage

variable lengh arrays are supported in C99 and optional in C11 but can cause portability issues, so prefer to use alloca() to allocate on the stack frame which is automatically freed when the function returns.

Was breaking macos unit test workflow.

Ticket: none
Changelog: none
@mender-test-bot

Copy link
Copy Markdown

There was an error running your pipeline, see logs for details.

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.

3 participants