]> git.imager.perl.org - imager.git/blobdiff - error.c
don't supply a default for a missing channel list
[imager.git] / error.c
diff --git a/error.c b/error.c
index 8ee422c0df24146419a031caae195124aeef1b2a..84785a2a2fd59d0a188b979198b84e55ec8cb991 100644 (file)
--- a/error.c
+++ b/error.c
@@ -188,7 +188,7 @@ the mark.
 
 Clears the error stack.
 
-Called by any imager function before doing any other processing.
+Called by any Imager function before doing any other processing.
 
 =cut
 */
@@ -222,7 +222,7 @@ error handling is calling function that does.).
 =cut
 */
 void i_push_error(int code, char const *msg) {
-  int size = strlen(msg)+1;
+  size_t size = strlen(msg)+1;
 
   if (error_sp <= 0)
     /* bad, bad programmer */
@@ -247,7 +247,7 @@ void i_push_error(int code, char const *msg) {
 }
 
 /*
-=item i_push_errorvf(int code, char const *fmt, va_list ap)
+=item i_push_errorvf(int C<code>, char const *C<fmt>, va_list C<ap>)
 
 =category Error handling
 
@@ -260,7 +260,9 @@ Does not support perl specific format codes.
 */
 void i_push_errorvf(int code, char const *fmt, va_list ap) {
   char buf[1024];
-#if defined(_MSC_VER)
+#if defined(IMAGER_VSNPRINTF)
+  vsnprintf(buf, sizeof(buf), fmt, ap);
+#elif defined(_MSC_VER)
   _vsnprintf(buf, sizeof(buf), fmt, ap);
 #else
   /* is there a way to detect vsnprintf()? 
@@ -277,7 +279,7 @@ void i_push_errorvf(int code, char const *fmt, va_list ap) {
 =synopsis i_push_errorf(errno, "Cannot open file %s: %d", filename, errno);
 =category Error handling
 
-A version of i_push_error() that does printf() like formating.
+A version of i_push_error() that does printf() like formatting.
 
 Does not support perl specific format codes.
 
@@ -315,7 +317,7 @@ int i_failed(int code, char const *msg) {
     failed_cb(error_stack + error_sp);
   if (failures_fatal) {
     int sp;
-    int total; /* total length of error messages */
+    size_t total; /* total length of error messages */
     char *full; /* full message for logging */
     if (argv0)
       fprintf(stderr, "%s: ", argv0);
@@ -329,7 +331,11 @@ int i_failed(int code, char const *msg) {
        i_fatal() */
     total = 1; /* remember the NUL */
     for (sp = error_sp; error_stack[sp].msg; ++sp) {
-      total += strlen(error_stack[sp].msg) + 2;
+      size_t new_total += strlen(error_stack[sp].msg) + 2;
+      if (new_total < total) {
+       /* overflow, somehow */
+       break;
+      }
     }
     full = mymalloc(total);
     if (!full) {