$OpenBSD$
--- src/SciTEBuffers.cxx.orig	Fri Mar 31 21:45:37 2006
+++ src/SciTEBuffers.cxx	Fri Mar 31 21:45:37 2006
@@ -376,14 +376,14 @@ void SciTEBase::InitialiseBuffers() {
 	}
 }
 
-static void EnsureEndsWithPathSeparator(char *path) {
+static void EnsureEndsWithPathSeparator(char *path, size_t path_size) {
 	size_t pathLen = strlen(path);
 	if ((pathLen > 0) && path[pathLen - 1] != pathSepChar) {
-		strcat(path, pathSepString);
+		strlcat(path, pathSepString, path_size);
 	}
 }
 
-static void RecentFilePath(char *path, const char *name) {
+static void RecentFilePath(char *path, size_t path_size, const char *name) {
 	char *where = getenv("SciTE_HOME");
 	if (!where)
 		where = getenv("HOME");
@@ -399,16 +399,16 @@ static void RecentFilePath(char *path, c
 #endif
 
 	} else {
-		strcpy(path, where);
-		EnsureEndsWithPathSeparator(path);
+		strlcpy(path, where, path_size);
+		EnsureEndsWithPathSeparator(path, path_size);
 	}
-	strcat(path, configFileVisibilityString);
-	strcat(path, name);
+	strlcat(path, configFileVisibilityString, path_size);
+	strlcat(path, name, path_size);
 }
 
 void SciTEBase::LoadRecentMenu() {
 	char recentPathName[MAX_PATH + 1];
-	RecentFilePath(recentPathName, recentFileName);
+	RecentFilePath(recentPathName, sizeof(recentPathName), recentFileName);
 	FILE *recentFile = fopen(recentPathName, fileRead);
 	if (!recentFile) {
 		DeleteFileStackMenu();
@@ -428,7 +428,7 @@ void SciTEBase::LoadRecentMenu() {
 
 void SciTEBase::SaveRecentStack() {
 	char recentPathName[MAX_PATH + 1];
-	RecentFilePath(recentPathName, recentFileName);
+	RecentFilePath(recentPathName, sizeof(recentPathName), recentFileName);
 	FILE *recentFile = fopen(recentPathName, fileWrite);
 	if (!recentFile)
 		return;
@@ -449,9 +449,9 @@ void SciTEBase::SaveRecentStack() {
 void SciTEBase::LoadSession(const char *sessionName) {
 	char sessionPathName[MAX_PATH + 1];
 	if (sessionName[0] == '\0') {
-		RecentFilePath(sessionPathName, defaultSessionFileName);
+		RecentFilePath(sessionPathName, sizeof(sessionPathName), defaultSessionFileName);
 	} else {
-		strcpy(sessionPathName, sessionName);
+		strlcpy(sessionPathName, sessionName, sizeof(sessionPathName));
 	}
 	FILE *sessionFile = fopen(sessionPathName, fileRead);
 	if (!sessionFile)
@@ -487,9 +487,9 @@ void SciTEBase::LoadSession(const char *
 void SciTEBase::SaveSession(const char *sessionName) {
 	char sessionPathName[MAX_PATH + 1];
 	if (sessionName[0] == '\0') {
-		RecentFilePath(sessionPathName, defaultSessionFileName);
+		RecentFilePath(sessionPathName, sizeof(sessionPathName), defaultSessionFileName);
 	} else {
-		strcpy(sessionPathName, sessionName);
+		strlcpy(sessionPathName, sessionName, sizeof(sessionPathName));
 	}
 	FILE *sessionFile = fopen(sessionPathName, fileWrite);
 	if (!sessionFile)
@@ -800,15 +800,15 @@ void SciTEBase::BuffersMenu() {
 #if PLAT_WIN
 
 			if (pos < 10) {
-				sprintf(entry, "&%d ", (pos + 1) % 10 ); // hotkey 1..0
-				sprintf(titleTab, "&%d ", (pos + 1) % 10); // add hotkey to the tabbar
+				snprintf(entry, sizeof(entry), "&%d ", (pos + 1) % 10 ); // hotkey 1..0
+				snprintf(titleTab, sizeof(entry), "&%d ", (pos + 1) % 10); // add hotkey to the tabbar
 			}
 #endif
 
 			if (buffers.buffers[pos].IsUntitled()) {
 				SString untitled = LocaliseString("Untitled");
-				strcat(entry, untitled.c_str());
-				strcat(titleTab, untitled.c_str());
+				strlcat(entry, untitled.c_str(), sizeof(entry));
+				strlcat(titleTab, untitled.c_str(), sizeof(titleTab));
 			} else {
 				SString path = buffers.buffers[pos].AsInternal();
 #if PLAT_WIN
@@ -820,22 +820,22 @@ void SciTEBase::BuffersMenu() {
 					amp += 2;
 				}
 #endif
-				strcat(entry, path.c_str());
+				strlcat(entry, path.c_str(), sizeof(entry));
 
 				char *cpDirEnd = strrchr(entry, pathSepChar);
 				if (cpDirEnd) {
-					strcat(titleTab, cpDirEnd + 1);
+					strlcat(titleTab, cpDirEnd + 1, sizeof(titleTab));
 				} else {
-					strcat(titleTab, entry);
+					strlcat(titleTab, entry, sizeof(titleTab));
 				}
 			}
 			// For short file names:
 			//char *cpDirEnd = strrchr(buffers.buffers[pos]->fileName, pathSepChar);
-			//strcat(entry, cpDirEnd + 1);
+			//strlcat(entry, cpDirEnd + 1, sizeof(entry));
 
 			if (buffers.buffers[pos].isDirty) {
-				strcat(entry, " *");
-				strcat(titleTab, " *");
+				strlcat(entry, " *", sizeof(entry));
+				strlcat(titleTab, " *", sizeof(titleTab));
 			}
 
 			SetMenuItem(menuBuffers, menuStart + pos + 1, itemID, entry);
@@ -900,10 +900,10 @@ void SciTEBase::SetFileStackMenu() {
 				entry[0] = '\0';
 #if PLAT_WIN
 
-				sprintf(entry, "&%d ", (stackPos + 1) % 10);
+				snprintf(entry, sizeof(entry), "&%d ", (stackPos + 1) % 10);
 #endif
 
-				strcat(entry, recentFileStack[stackPos].AsInternal());
+				strlcat(entry, recentFileStack[stackPos].AsInternal(), sizeof(entry));
 				SetMenuItem(menuFile, MRU_START + stackPos + 1, itemID, entry);
 			}
 		}
@@ -1320,8 +1320,7 @@ int DecodeMessage(char *cdoc, char *sour
 			char *endPath = strchr(startPath, '\"');
 			int length = endPath - startPath;
 			if (length > 0) {
-				strncpy(sourcePath, startPath, length);
-				sourcePath[length] = 0;
+				strlcpy(sourcePath, startPath, length);
 			}
 			endPath++;
 			while (*endPath && !isdigitchar(*endPath)) {
@@ -1340,8 +1339,7 @@ int DecodeMessage(char *cdoc, char *sour
 				if (cdoc[i] == ':' && isdigitchar(cdoc[i + 1])) {
 					int sourceNumber = atoi(cdoc + i + 1) - 1;
 					if (i > 0) {
-						strncpy(sourcePath, cdoc, i);
-						sourcePath[i] = 0;
+						strlcpy(sourcePath, cdoc, i);
 					}
 					return sourceNumber;
 				}
@@ -1357,8 +1355,7 @@ int DecodeMessage(char *cdoc, char *sour
 			char *endPath = strchr(start, '(');
 			int length = endPath - start;
 			if ((length > 0) && (length < MAX_PATH)) {
-				strncpy(sourcePath, start, length);
-				sourcePath[length] = 0;
+				strlcpy(sourcePath, start, length);
 			}
 			endPath++;
 			return atoi(endPath) - 1;
@@ -1395,8 +1392,7 @@ int DecodeMessage(char *cdoc, char *sour
 					int length = space2 - space;
 
 					if (length > 0) {
-						strncpy(sourcePath, space, length);
-						sourcePath[length] = '\0';
+						strlcpy(sourcePath, space, length);
 						return atoi(space2) - 1;
 					}
 				}
@@ -1409,8 +1405,7 @@ int DecodeMessage(char *cdoc, char *sour
 			char *line = strstr(cdoc, " line ");
 			int length = line - (at + 4);
 			if (at && line && length > 0) {
-				strncpy(sourcePath, at + 4, length);
-				sourcePath[length] = 0;
+				strlcpy(sourcePath, at + 4, length);
 				line += 6;
 				return atoi(line) - 1;
 			}
@@ -1422,8 +1417,7 @@ int DecodeMessage(char *cdoc, char *sour
 			char *line = strstr(cdoc, ":line ");
 			if (in && line && (line > in)) {
 				in += 4;
-				strncpy(sourcePath, in, line - in);
-				sourcePath[line - in] = 0;
+				strlcpy(sourcePath, in, line - in);
 				line += 6;
 				return atoi(line) - 1;
 			}
@@ -1441,8 +1435,7 @@ int DecodeMessage(char *cdoc, char *sour
 				char *quote = strstr(fileStart, "'");
 				size_t length = quote - fileStart;
 				if (quote && length > 0) {
-					strncpy(sourcePath, fileStart, length);
-					sourcePath[length] = '\0';
+					strlcpy(sourcePath, fileStart, length);
 				}
 				line += lenLine;
 				return atoi(line) - 1;
@@ -1460,8 +1453,7 @@ int DecodeMessage(char *cdoc, char *sour
 					if (strchr("\t\n\r \"$%'*,;<>?[]^`{|}", cdoc[j])) {
 						j++;
 					}
-					strncpy(sourcePath, &cdoc[j], i - j);
-					sourcePath[i - j] = 0;
+					strlcpy(sourcePath, &cdoc[j], i - j);
 					// Because usually the address is a searchPattern, lineNumber has to be evaluated later
 					return 0;
 				}
@@ -1478,8 +1470,7 @@ int DecodeMessage(char *cdoc, char *sour
 			if (line && file && (line > file)) {
 				file += lenFile;
 				size_t length = line - file;
-				strncpy(sourcePath, file, length);
-				sourcePath[length] = '\0';
+				strlcpy(sourcePath, file, length);
 				line += lenLine;
 				return atoi(line) - 1;
 			}
@@ -1502,8 +1493,7 @@ int DecodeMessage(char *cdoc, char *sour
 						file++;
 					}
 					size_t length = strlen(file);
-					strncpy(sourcePath, file, length);
-					sourcePath[length] = '\0';
+					strlcpy(sourcePath, file, length);
 					return atoi(line) - 1;
 				}
 			}
@@ -1526,8 +1516,7 @@ int DecodeMessage(char *cdoc, char *sour
 				file++;
 				char *endfile = strchr(file, ')');
 				size_t length = endfile - file;
-				strncpy(sourcePath, file, length);
-				sourcePath[length] = '\0';
+				strlcpy(sourcePath, file, length);
 				line++;
 				return atoi(line) - 1;
 			}
@@ -1547,11 +1536,10 @@ int DecodeMessage(char *cdoc, char *sour
 			if (line && file && (line > file)) {
 				file += lenFile;
 				size_t length = line - file;
-				strncpy(sourcePath, file, length);
-				sourcePath[length] = '\0';
+				strlcpy(sourcePath, file, length);
 				line += lenLine;
 				length = column - line;
-				strncpy(line, line, length);
+				strlcpy(line, line, length);
 				return atoi(line) - 1;
 			}
 			break;
@@ -1571,12 +1559,11 @@ int DecodeMessage(char *cdoc, char *sour
 			if (line && file && (line > file)) {
 				file += lenFile;
 				size_t length = line - file;
-				strncpy(sourcePath, file, length);
-				sourcePath[length] = '\0';
+				strlcpy(sourcePath, file, length);
 				line += lenLine;
 				if ((lineend > line)) {
 					length = lineend - line;
-					strncpy(line, line, length);
+					strlcpy(line, line, length);
 					return atoi(line) - 1;
 				}
 			}
@@ -1616,8 +1603,7 @@ int DecodeMessage(char *cdoc, char *sour
 			char *endPath = strchr(startPath, ':');
 			int length = endPath - startPath;
 			if (length > 0) {
-				strncpy(sourcePath, startPath, length);
-				sourcePath[length] = 0;
+				strlcpy(sourcePath, startPath, length);
 				int sourceNumber = atoi(endPath+1) - 1;
 				return sourceNumber;
 			}
@@ -1631,8 +1617,7 @@ int DecodeMessage(char *cdoc, char *sour
 			char *endPath = strchr(startPath, '\t');
 			if (endPath) {
 				int length = endPath - startPath;
-				strncpy(sourcePath, startPath, length);
-				sourcePath[length] = 0;
+				strlcpy(sourcePath, startPath, length);
 				return 0;
 			}
 			break;
