summaryrefslogtreecommitdiff
path: root/apt-pkg/contrib/error.cc
diff options
context:
space:
mode:
authorDavid Kalnischkies <kalnischkies@gmail.com>2011-02-07 21:42:36 +0100
committerDavid Kalnischkies <kalnischkies@gmail.com>2011-02-07 21:42:36 +0100
commit8f3853baea6191788da6befb437e92ba246c86a3 (patch)
tree6c3edf065be2c8eca709b57e4bcb74ff6b90f9d9 /apt-pkg/contrib/error.cc
parentcfe35dbc01015c6927193fd5da02eaabd753989a (diff)
* apt-pkg/contrib/error.cc:
- remove 400 char size limit of error messages (LP: #365611)
Diffstat (limited to 'apt-pkg/contrib/error.cc')
-rw-r--r--apt-pkg/contrib/error.cc31
1 files changed, 25 insertions, 6 deletions
diff --git a/apt-pkg/contrib/error.cc b/apt-pkg/contrib/error.cc
index e2e8d6e57..7dad11689 100644
--- a/apt-pkg/contrib/error.cc
+++ b/apt-pkg/contrib/error.cc
@@ -18,6 +18,7 @@
#include <iostream>
#include <errno.h>
#include <stdio.h>
+#include <stdlib.h>
#include <unistd.h>
#include <string>
@@ -103,10 +104,21 @@ bool GlobalError::InsertErrno(MsgType const &type, const char *Function,
// GlobalError::InsertErrno - formats an error message with the errno /*{{{*/
bool GlobalError::InsertErrno(MsgType type, const char* Function,
const char* Description, va_list &args) {
- char S[400];
- snprintf(S, sizeof(S), "%s - %s (%i: %s)", Description,
- Function, errno, strerror(errno));
- return Insert(type, S, args);
+ int const errsv = errno;
+ char* S = (char*) malloc(400);
+ size_t const Ssize = snprintf(S, 400, "%s - %s (%i: %s)", Description,
+ Function, errsv, strerror(errsv)) + 1;
+
+ if (Ssize > 400) {
+ free(S);
+ S = (char*) malloc(Ssize);
+ snprintf(S, Ssize, "%s - %s (%i: %s)", Description,
+ Function, errsv, strerror(errsv));
+ }
+
+ bool const geins = Insert(type, S, args);
+ free(S);
+ return geins;
}
/*}}}*/
// GlobalError::Fatal - Add a fatal error to the list /*{{{*/
@@ -157,8 +169,14 @@ bool GlobalError::Insert(MsgType const &type, const char *Description,...)
// GlobalError::Insert - Insert a new item at the end /*{{{*/
bool GlobalError::Insert(MsgType type, const char* Description,
va_list &args) {
- char S[400];
- vsnprintf(S,sizeof(S),Description,args);
+ char* S = (char*) malloc(400);
+ size_t const Ssize = vsnprintf(S, 400, Description, args) + 1;
+
+ if (Ssize > 400) {
+ free(S);
+ S = (char*) malloc(Ssize);
+ vsnprintf(S, Ssize, Description, args);
+ }
Item const m(S, type);
Messages.push_back(m);
@@ -169,6 +187,7 @@ bool GlobalError::Insert(MsgType type, const char* Description,
if (type == FATAL || type == DEBUG)
std::clog << m << std::endl;
+ free(S);
return false;
}
/*}}}*/