src/fingerprint.c |   25 +++++++++++++------------
 1 file changed, 13 insertions(+), 12 deletions(-)

New commits:
commit 42dded870aaeee937d055dae3bd988a1a6ef2257
Author:     Caolán McNamara <[email protected]>
AuthorDate: Sat May 16 12:09:49 2026 +0100
Commit:     Caolán McNamara <[email protected]>
CommitDate: Sat May 16 13:13:15 2026 +0200

    respect bufsize in prepbuffer
    
    Change-Id: I3d83d1ceb261c2d5857b37831a9189c0b5957366
    Reviewed-on: https://gerrit.libreoffice.org/c/libexttextcat/+/205236
    Tested-by: Caolán McNamara <[email protected]>
    Reviewed-by: Caolán McNamara <[email protected]>

diff --git a/src/fingerprint.c b/src/fingerprint.c
index 3c8d242..108edcb 100644
--- a/src/fingerprint.c
+++ b/src/fingerprint.c
@@ -351,17 +351,18 @@ extern const char *fp_Name(void *handle)
 static char *prepbuffer(const char *src, size_t bufsize, uint4 mindocsize)
 {
     const char *p = src;
+    const char *plimit = src + bufsize;
     char *dest = (char *)malloc(bufsize + 3);
     char *w = dest;
     char *wlimit = dest + bufsize + 1;
 
-    if (INVALID(*p))
+    if (p == plimit || *p == '
     {
-        goto SPACE;
+        goto END;
     }
-    else if (*p == '
+    else if (INVALID(*p))
     {
-        goto END;
+        goto SPACE;
     }
 
     *w++ = '_';
@@ -376,13 +377,13 @@ static char *prepbuffer(const char *src, size_t bufsize, 
uint4 mindocsize)
   SPACE:
     /*** Inside string of invalid characters ***/
     p++;
-    if (INVALID(*p))
+    if (p == plimit || *p == '
     {
-        goto SPACE;
+        goto END;
     }
-    else if (*p == '
+    else if (INVALID(*p))
     {
-        goto END;
+        goto SPACE;
     }
 
     *w++ = '_';
@@ -400,13 +401,13 @@ static char *prepbuffer(const char *src, size_t bufsize, 
uint4 mindocsize)
     {
         goto END;
     }
-    else if (INVALID(*p))
+    else if (p == plimit || *p == '
     {
-        goto SPACE;
+        goto STOP;
     }
-    else if (*p == '
+    else if (INVALID(*p))
     {
-        goto STOP;
+        goto SPACE;
     }
     goto WORD;
 

Reply via email to