Skip to content

Refuse set() on a read-only instance - #1700

Merged
lingol merged 1 commit into
Tencent:devfrom
lenamonj:read-only-set-refused
Oct 26, 2026
Merged

lingol merged 1 commit into
Tencent:devfrom
lenamonj:read-only-set-refused

Conversation

@lenamonj

Copy link
Copy Markdown

On an instance opened with MMKV_READ_ONLY, set() that overwrites the only key of a single-process store writes into the read-only mapping and the process dies on the write fault. The append path refuses read-only inside ensureMemorySize(), but that overwrite takes the in-place override path, which never grows the file.

setDataForKey, which every set() overload reaches, now returns false on a read-only instance with the same warning removeValueForKey and removeValuesForKeys give.

The new testReadOnlyRejectsSet in POSIX/demo/UnitTest.cpp kills UnitTest on dev (SIGSEGV on Linux) and passes with the change; the four ctest targets pass.

@lingol
lingol merged commit ef88ee1 into Tencent:dev Oct 26, 2026
1 check passed
@lenamonj
lenamonj deleted the read-only-set-refused branch October 26, 2026 21:33
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.

2 participants