$OpenBSD: patch-gtk_PlatGTK_cxx,v 1.2 2007/01/18 10:56:27 steven Exp $
--- gtk/PlatGTK.cxx.orig	Tue Mar 28 17:31:51 2006
+++ gtk/PlatGTK.cxx	Tue Mar 28 17:31:51 2006
@@ -351,7 +351,7 @@ static void GenerateFontSpecStrings(cons
 	if (strchr(fontName, '-')) {
 		char tmp[300];
 		char *d1 = NULL, *d2 = NULL, *d3 = NULL;
-		strncpy(tmp, fontName, sizeof(tmp) - 1);
+		strlcpy(tmp, fontName, sizeof(tmp));
 		d1 = strchr(tmp, '-');
 		// we know the first dash exists
 		d2 = strchr(d1 + 1, '-');
@@ -362,25 +362,25 @@ static void GenerateFontSpecStrings(cons
 			*d2 = '\0';
 			foundary[0] = '-';
 			foundary[1] = '\0';
-			strncpy(faceName, tmp, foundary_len - 1);
-			strncpy(charset, d2 + 1, charset_len - 1);
+			strlcpy(faceName, tmp, foundary_len);
+			strlcpy(charset, d2 + 1, charset_len);
 		} else if (d2) {
 			// fontface-isoxxx-x
 			*d1 = '\0';
-			strcpy(foundary, "-*-");
-			strncpy(faceName, tmp, faceName_len - 1);
-			strncpy(charset, d1 + 1, charset_len - 1);
+			strlcpy(foundary, "-*-", foundary_len);
+			strlcpy(faceName, tmp, faceName_len);
+			strlcpy(charset, d1 + 1, charset_len);
 		} else {
 			// foundary-fontface
 			foundary[0] = '-';
 			foundary[1] = '\0';
-			strncpy(faceName, tmp, faceName_len - 1);
-			strncpy(charset, CharacterSetName(characterSet), charset_len - 1);
+			strlcpy(faceName, tmp, faceName_len);
+			strlcpy(charset, CharacterSetName(characterSet), charset_len);
 		}
 	} else {
-		strncpy(foundary, "-*-", foundary_len);
-		strncpy(faceName, fontName, faceName_len - 1);
-		strncpy(charset, CharacterSetName(characterSet), charset_len - 1);
+		strlcpy(foundary, "-*-", foundary_len);
+		strlcpy(faceName, fontName, faceName_len);
+		strlcpy(charset, CharacterSetName(characterSet), charset_len);
 	}
 }
 
@@ -390,7 +390,7 @@ static void SetLogFont(LOGFONT &lf, cons
 	lf.bold = bold;
 	lf.italic = italic;
 	lf.characterSet = characterSet;
-	strncpy(lf.faceName, faceName, sizeof(lf.faceName) - 1);
+	strlcpy(lf.faceName, faceName, sizeof(lf.faceName));
 }
 
 /**
@@ -552,9 +552,8 @@ FontID FontCached::CreateNewFont(const c
 	// eg. adobe-courier-iso10646-1,*-courier-iso10646-1,*-*-*-*
 	if (strchr(fontName, ',')) {
 		// build a fontspec and use gdk_fontset_load
-		int remaining = sizeof(fontset);
 		char fontNameCopy[1024];
-		strncpy(fontNameCopy, fontName, sizeof(fontNameCopy) - 1);
+		strlcpy(fontNameCopy, fontName, sizeof(fontNameCopy));
 		char *fn = fontNameCopy;
 		char *fp = strchr(fn, ',');
 		for (;;) {
@@ -585,8 +584,7 @@ FontID FontCached::CreateNewFont(const c
 			// we are doing italic, add an oblique font
 			// to the list
 			if (italic && fontset[0] == '\0') {
-				strncat(fontset, fontspec, remaining - 1);
-				remaining -= strlen(fontset);
+				strlcat(fontset, fontspec, sizeof(fontset));
 
 				snprintf(fontspec,
 				         sizeof(fontspec) - 1,
@@ -597,8 +595,7 @@ FontID FontCached::CreateNewFont(const c
 				         charset);
 			}
 
-			strncat(fontset, fontspec, remaining - 1);
-			remaining -= strlen(fontset);
+			strlcat(fontset, fontspec, sizeof(fontset));
 
 			if (!fp)
 				break;
@@ -2394,8 +2391,7 @@ void ListBoxX::GetValue(int n, char *val
 	}
 #endif
 	if (text && len > 0) {
-		strncpy(value, text, len);
-		value[len - 1] = '\0';
+		strlcpy(value, text, len);
 	} else {
 		value[0] = '\0';
 	}
@@ -2668,7 +2664,7 @@ void Platform::DebugPrintf(const char *f
 	char buffer[2000];
 	va_list pArguments;
 	va_start(pArguments, format);
-	vsprintf(buffer, format, pArguments);
+	vsnprintf(buffer, sizeof(buffer), format, pArguments);
 	va_end(pArguments);
 	Platform::DebugDisplay(buffer);
 }
@@ -2688,8 +2684,7 @@ bool Platform::ShowAssertionPopUps(bool 
 
 void Platform::Assert(const char *c, const char *file, int line) {
 	char buffer[2000];
-	sprintf(buffer, "Assertion [%s] failed at %s %d", c, file, line);
-	strcat(buffer, "\r\n");
+	snprintf(buffer, sizeof(buffer), "Assertion [%s] failed at %s %d\r\n", c, file, line);
 	Platform::DebugDisplay(buffer);
 	abort();
 }
