$OpenBSD: patch-jhead_c,v 1.3 2004/07/18 20:21:03 xsa Exp $
--- jhead.c.orig	Mon Jul  5 19:28:00 2004
+++ jhead.c	Fri Jul 16 09:28:54 2004
@@ -153,7 +153,8 @@ static int FileEditComment(char * TempFi
 #endif
         }
 
-        sprintf(QuotedPath, "%s \"%s\"",Editor, TempFileName);
+        snprintf(QuotedPath, sizeof QuotedPath, "%s \"%s\"",
+		Editor, TempFileName);
         a = system(QuotedPath);
     }
     
@@ -260,7 +261,8 @@ static int ModifyDescriptComment(char * 
     if (!HasScandate && !ImageInfo.DateTime[0]){
         // Scan date is not in the file yet, and it doesn't have one built in.  Add it.
         char Temp[30];
-        sprintf(Temp, "scan_date=%s", ctime(&ImageInfo.FileDateTime));
+        snprintf(Temp, sizeof Temp, "scan_date=%s",
+		ctime(&ImageInfo.FileDateTime));
         strcat(OutComment, Temp);
         Modified = TRUE;
     }
@@ -288,7 +290,9 @@ static int AutoResizeCmdStuff(void)
 
     if (scale > 0.8) return FALSE; // Don't rescale by really small amounts (not worth it!)
 
-    sprintf(CommandString, "mogrify -geometry %dx%d -quality 80 &i",(int)(ImageInfo.Width*scale), (int)(ImageInfo.Height*scale));
+    snprintf(CommandString, sizeof CommandString,
+	"mogrify -geometry %dx%d -quality 80 &i",
+	(int)(ImageInfo.Width*scale), (int)(ImageInfo.Height*scale));
     return TRUE;
 }
 
@@ -319,17 +323,20 @@ static void DoCommand(const char * FileN
             if (ApplyCommand[a+1] == 'i'){
                 // Input file.
                 if (strstr(FileName, " ")){
-                    e += sprintf(ExecString+e, "\"%s\"",FileName);
+                    e += snprintf(ExecString+e, sizeof ExecString+e,
+			"\"%s\"",FileName);
                 }else{
                     // No need for quoting (that way I can put a relative path in front)
-                    e += sprintf(ExecString+e, "%s",FileName);
+                    e += snprintf(ExecString+e, sizeof ExecString+e,
+			"%s",FileName);
                 }
                 a += 1;
                 continue;
             }
             if (ApplyCommand[a+1] == 'o'){
                 // Needs an output file distinct from the input file.
-                e += sprintf(ExecString+e, "\"%s\"",TempName);
+                e += snprintf(ExecString+e, sizeof ExecString+e, 
+			"\"%s\"",TempName);
                 a += 1;
                 TempUsed = TRUE;
                 unlink(TempName);// Remove any pre-existing temp file
@@ -494,7 +501,7 @@ void DoFileRenaming(const char * FileNam
                         char num[16];
                         memcpy(pat, pattern+ppos, 4);
                         pat[a-ppos+1] = '\0';
-                        sprintf(num, pat, FilesMatched); // let printf do the number formatting.
+                        snprintf(num, sizeof num, pat, FilesMatched); // let printf do the number formatting.
                         memmove(pattern+ppos+strlen(num), pattern+a+1, strlen(pattern+a+1)+1);
                         memcpy(pattern+ppos, num, strlen(num));
                         break;
@@ -508,7 +515,8 @@ void DoFileRenaming(const char * FileNam
         strftime(NewBaseName+PrefixPart, PATH_MAX, pattern, &tm);
     }else{
         // My favourite scheme.
-        sprintf(NewBaseName+PrefixPart, "%02d%02d-%02d%02d%02d",
+        snprintf(NewBaseName+PrefixPart, sizeof NewBaseName+PrefixPart,
+		"%02d%02d-%02d%02d%02d",
              tm.tm_mon+1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
     }
 
@@ -533,7 +541,7 @@ void DoFileRenaming(const char * FileNam
             NameExtra[0] = 0;
         }
 
-        sprintf(NewName, "%s%s.jpg", NewBaseName, NameExtra);
+        snprintf(NewName, sizeof NewName, "%s%s.jpg", NewBaseName, NameExtra);
 
         if (!strcmp(FileName, NewName)) break; // Skip if its already this name.
 
@@ -617,7 +625,8 @@ void ProcessFile(const char * FileName)
                     if (Argument == NULL){
                         ErrFatal("Orientation screwup");
                     }
-                    sprintf(RotateCommand, "jpegtran -%s -outfile &o &i", Argument);
+                    snprintf(RotateCommand, sizeof RotateCommand,
+			"jpegtran -%s -outfile &o &i", Argument);
                     ApplyCommand = RotateCommand;
                     DoCommand(FileName);
                     ApplyCommand = NULL;
@@ -838,7 +847,7 @@ void ProcessFile(const char * FileName)
 
             // Print to temp buffer first to avoid putting null termination in destination.
             // snprintf() would do the trick ,but not available everywhere (like FreeBSD 4.4)
-            sprintf(TempBuf, "%04d:%02d:%02d %02d:%02d:%02d",
+            snprintf(TempBuf, sizeof TempBuf, "%04d:%02d:%02d %02d:%02d:%02d",
                 tm.tm_year+1900, tm.tm_mon+1, tm.tm_mday,
                 tm.tm_hour, tm.tm_min, tm.tm_sec);
 
