Skip to content

fix(core): set_if_needed updates an empty cached context#10098

Merged
rc-swag merged 2 commits intomasterfrom
fix/core/set-if-needed-handles-cleared-cache
Nov 30, 2023
Merged

fix(core): set_if_needed updates an empty cached context#10098
rc-swag merged 2 commits intomasterfrom
fix/core/set-if-needed-handles-cleared-cache

Conversation

@rc-swag
Copy link
Copy Markdown
Contributor

@rc-swag rc-swag commented Nov 30, 2023

In the case where the cached context had been cleared the km_core_state_context_set_if_needed call would just compare the null terminations of both strings and not set the cached context to the application context.

I first thought I could just change the decrement of the pointers to occur before the iteration not after e.g.


for(; context_p > context && cached_context_p > cached_context; --context_p, --cached_context_p) {
    if(*context_p != *cached_context_p) {
      // The cached context doesn't match the application context, so it is
      // invalid
      return false;
    }
  }

This skips the comparing the null, however it will still also drop out and return true. It is just quicker to bail if the cached context is an "empty" string.
I also considered renaming is_context_valid to is_context_update_needed.

@keymanapp-test-bot skip

In the case when the cached context had been cleared the
km_core_state_context_set_if_needed call would just compare
the null terminations of both strings and not set the cached
context to the application context.
@rc-swag rc-swag added this to the A17S27 milestone Nov 30, 2023
@keymanapp-test-bot keymanapp-test-bot bot added the user-test-missing User tests have not yet been defined for the PR label Nov 30, 2023
@keymanapp-test-bot
Copy link
Copy Markdown

keymanapp-test-bot bot commented Nov 30, 2023

User Test Results

Test specification and instructions

User tests are not required

@rc-swag rc-swag marked this pull request as ready for review November 30, 2023 03:23
@rc-swag rc-swag requested a review from mcdurdin as a code owner November 30, 2023 03:23
@github-actions github-actions bot added core/ Keyman Core fix labels Nov 30, 2023
@keymanapp-test-bot keymanapp-test-bot bot removed the user-test-missing User tests have not yet been defined for the PR label Nov 30, 2023
Copy link
Copy Markdown
Member

@mcdurdin mcdurdin left a comment

Choose a reason for hiding this comment

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

LGTM. @sgschantz does this look right to you too?

Co-authored-by: Marc Durdin <marc@durdin.net>
@rc-swag rc-swag merged commit 5351abb into master Nov 30, 2023
@rc-swag rc-swag deleted the fix/core/set-if-needed-handles-cleared-cache branch November 30, 2023 03:56
Copy link
Copy Markdown
Contributor

@sgschantz sgschantz left a comment

Choose a reason for hiding this comment

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

LGTM

@keyman-server
Copy link
Copy Markdown
Collaborator

Changes in this pull request will be available for download in Keyman version 17.0.220-alpha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core/ Keyman Core fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants