File fix4bug1241684.patch of Package gnuplot.38691

commit a5897feadc4be73b0ffd8458556c47117bd24d03
Author: Ethan A Merritt <merritt@u.washington.edu>
Date:   Tue Mar 25 22:51:54 2025 -0700

    hpgl: font name parsing overruns the string by one char
    
    if no comma is present in the font name.
    E.g.
       set term pcl
       set title "Title" font "sans"    # no comma in font name
       plot x
    
    Bug 2781

---
 term/hpgl.trm |   28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

--- term/hpgl.trm
+++ term/hpgl.trm	2025-05-14 08:27:21.384046200 +0000
@@ -1321,8 +1321,12 @@ HPGL2_set_font(const char *font)
 {
     struct termentry *t = term;
     char name[MAX_ID_LEN + 1];
-    int i, sep, int_size, sep2;
-    double size;
+    int i;
+    char *sep;
+    double size = HPGL2_point_size;
+
+    if (font == NULL)
+	font = "";
 /*
  * If in Polyline Encoded command, leave Polyline Encoded command
  */
@@ -1330,24 +1334,24 @@ HPGL2_set_font(const char *font)
 	fputs(";\n", gpoutfile);
 	HPGL2_in_pe = 0;
     }
+/* determine font size, use default from options if invalid */
+    sep = strchr(font, ',');
+    if (sep) {
+	double req_size = strtod(sep+1, NULL);
+	if (req_size > 0)
+	    size = req_size;
+	*sep = '\0';
+    }
 /* determine font, use default from options if invalid */
-    sep = strcspn(font, ",");
-    strncpy(name, font, sep);
-    name[sep] = NUL;
+    strncpy(name, font, sizeof(name)-1);
     for (i = 0; i < HPGL2_FONTS; i++) {
+	int sep2;
 	sep2 = strcspn(HPGL2_font_table[i].compare, "$");
 	if (strncmp(name, HPGL2_font_table[i].compare, sep2) == 0)
 	    break;
     }
     if (i >= HPGL2_FONTS)
 	i = HPGL2_font_num;
-/* determine font size, use default from options if invalid */
-    int_size = 0;
-    sscanf(&(font[sep + 1]), "%d", &int_size);
-    if (int_size > 0) {
-	size = int_size;
-    } else
-	size = HPGL2_point_size;
 /* apply font changes only if necessary */
     if (size == HPGL2_point_size_current && i == HPGL2_font_num_current)
 	return FALSE;
openSUSE Build Service is sponsored by