[Scummvm-git-logs] scummvm master -> 09c7c07d32ca06c1d0bc47bb36daf149d57a5768
a-yyg
76591232+a-yyg at users.noreply.github.com
Mon Aug 2 22:38:56 UTC 2021
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
09c7c07d32 SAGA2: Fix pointer arithmetic in GTextWrap
Commit: 09c7c07d32ca06c1d0bc47bb36daf149d57a5768
https://github.com/scummvm/scummvm/commit/09c7c07d32ca06c1d0bc47bb36daf149d57a5768
Author: a/ (yuri.kgpps at gmail.com)
Date: 2021-08-03T07:36:03+09:00
Commit Message:
SAGA2: Fix pointer arithmetic in GTextWrap
Changed paths:
engines/saga2/gtext.cpp
diff --git a/engines/saga2/gtext.cpp b/engines/saga2/gtext.cpp
index 798d6a8d19..99eb64bb31 100644
--- a/engines/saga2/gtext.cpp
+++ b/engines/saga2/gtext.cpp
@@ -898,45 +898,52 @@ int16 WhichIChar(gFont *font, uint8 *s, int16 length, int16 maxLen) {
**********************************************************************
*/
int32 GTextWrap(gFont *font, char *mark, uint16 &count, uint16 width, int16 styles) {
- char *text = mark;
- char *ntext, *atext, *ltext;
- uint16 pixlen;
+ char *text = mark;
+ char *atext;
+ uint16 pixlen;
+ int aTextIndex = 0;
if (!strchr(text, '\n')) {
count = strlen(text);
pixlen = TextWidth(font, text, count, styles);
- if (pixlen <= width) return -1;
+ if (pixlen <= width)
+ return -1;
}
atext = text;
while (1) {
- ntext = strchr(atext, ' ');
- ltext = strchr(atext, '\n');
+ Common::String s = atext;
- if (ntext == NULL || (ltext != NULL && ltext < ntext)) {
- pixlen = TextWidth(font, text, ltext - text, styles);
+ int nTextIndex = aTextIndex + s.findFirstOf(' ');
+ int lTextIndex = aTextIndex + s.findFirstOf('\n');
+
+ if (!s.contains(' ') || (s.contains('\n') && lTextIndex < nTextIndex)) {
+ pixlen = TextWidth(font, text, lTextIndex, styles);
if (pixlen <= width) {
- count = ltext - text;
+ count = lTextIndex;
return count + 1;
}
- if (ntext == NULL) {
- if (atext == text) break;
+ if (!s.contains(' ')) {
+ if (atext == text)
+ break;
- count = atext - text - 1;
+ count = aTextIndex - 1;
return count + 1;
}
}
- pixlen = TextWidth(font, text, ntext - text, styles);
+ pixlen = TextWidth(font, text, nTextIndex, styles);
if (pixlen > width) {
- if (atext == text) break;
+ if (atext == text)
+ break;
- count = atext - text - 1;
+ count = aTextIndex - 1;
return count + 1;
}
- atext = ntext + 1;
+ atext = text + nTextIndex + 1;
+ aTextIndex = nTextIndex + 1;
}
if (atext == text) {
@@ -945,10 +952,11 @@ int32 GTextWrap(gFont *font, char *mark, uint16 &count, uint16 width, int16 styl
count = strlen(text);
while (--count) {
pixlen = TextWidth(font, text, count, styles);
- if (pixlen <= width) return count;
+ if (pixlen <= width)
+ return count;
}
} else {
- count = atext - text - 1;
+ count = aTextIndex - 1;
return count + 1;
}
More information about the Scummvm-git-logs
mailing list