-
Notifications
You must be signed in to change notification settings - Fork 370
fix: special slf not displays as expected #280
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
base: master
Are you sure you want to change the base?
Conversation
31445b3 to
0a5e945
Compare
by changing msgbuf implementation to nullable array
0a5e945 to
c316367
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes handling of special SLF message IDs so mods with non-sequential or high IDs display correctly. It also increases the message buffer size and improves safe freeing of message strings.
- MESSAGE_MAX_BUFFER_SIZE raised from 512 to 1024
- Introduced
maxIDtracking to computeg_TextLib.nMsgsover non-sequential IDs - Adjusted allocation and free loops for
lpMsgBufbased on the newnMsgs
Comments suppressed due to low confidence (4)
text.c:40
- [nitpick] Consider adding a comment explaining why
MESSAGE_MAX_BUFFER_SIZEwas increased from 512 to 1024 so future maintainers understand the rationale.
#define MESSAGE_MAX_BUFFER_SIZE 1024
text.c:561
- Add unit tests for message files with non-sequential or very large ID values to verify that the new
nMsgscalculation correctly allocates space for all indices.
g_TextLib.nMsgs = max(maxID, msg_cnt) + 1;
text.c:267
- The standard C library doesn't provide a
maxmacro by default. Either include or define a portableMAXmacro (or use(maxID > eid ? maxID : eid)) to avoid compilation errors.
maxID = max(maxID, eid);
text.c:561
- Similar to the earlier use of
max, ensure aMAXmacro is defined or replace this with an inline conditional expression to guarantee portability and correct sizing.
g_TextLib.nMsgs = max(maxID, msg_cnt) + 1;
| if (msg->value) | ||
| { | ||
| g_TextLib.lpIndexBuf[item->index][item->indexEnd - item->index][index++] = idx_msg; | ||
| assert(idx_msg < g_TextLib.nMsgs); |
Copilot
AI
Jun 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Relying solely on assert means this bounds check is removed in release builds. Consider adding an explicit runtime check or error handling to prevent potential buffer overflow in production.
| assert(idx_msg < g_TextLib.nMsgs); | |
| if (idx_msg >= g_TextLib.nMsgs) { | |
| fprintf(stderr, "Error: idx_msg (%d) exceeds g_TextLib.nMsgs (%d). Potential buffer overflow.\n", idx_msg, g_TextLib.nMsgs); | |
| exit(EXIT_FAILURE); | |
| } |
Test Cases( from @PalAlexx ):
pal98.zip
Test method: Replace the files and open any save file(.RPG) that any PC have the magic "CoinDartII(乾坤一掷)", see its (altered) description in magic menu.
Expected: two line 10/11 seen
Actually (before this PR merged): nothing
Explanation: This mod appends two new messages(and its indexes too) to the ending, and let two previous-existing message index (second argument of 0xffff script command) points to the new ones. It makes the count-based g_TextLib.nMsgs (incorrctly) keeps not changes( since there was two old one not used, and two new one added ), which denies new added messages from displaying.
abnormal.zip
Test Method: Replace the files and begin a new game session, look at the first 3 lines Li's Aunt said
Expected:
Actually (before this PR merged):
Explanation: This mod directly modify the message index scripts and the corresponding sid/eid of the corresponding block in the generated slf . But the modified number numbers are far bigger than(14702/14703) the counted nMsgs(12xxx), which denies the index-moved messages from displaying.
What this patch did:
Instead of counting, makes nMsgs be the max number of all the IDs, and allow the middle message be null, in order to make the two kind of mod works.
NEED TESTS:
Since this patch seems affects whole lifecycle of the game, I request review from other admins, or wide tests from whole society to ensure it may not introducing new bugs.
Have you checked to ensure there aren't other open Pull Requests for the same change?
Have you added an explanation of what your changes do and why you'd like us to include them?
How many dependencies was introduced in this PR? Did the minimal requirement changed, for which platform?
0
Have you written new tests for your changes?
Have you successfully run it with your changes locally?
Have you tested on following platforms?
I certify that I have the right and agree to submit my contributions under the terms of GNU General Public License, version 3 (or any later version at the choice of the maintainers of the SDLPAL Project) as published by the Free Software Foundation.