aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGreg Hudson <ghudson@mit.edu>2009-11-01 22:32:47 +0000
committerGreg Hudson <ghudson@mit.edu>2009-11-01 22:32:47 +0000
commit36d48179639fcf05a250ed973eaebfa3d4348a25 (patch)
treebe6c3f5512f23efc34e79477ff2f1a823499141a
parentcf976d22466992d54689f93e7af9c47786549ccc (diff)
downloadkrb5-36d48179639fcf05a250ed973eaebfa3d4348a25.zip
krb5-36d48179639fcf05a250ed973eaebfa3d4348a25.tar.gz
krb5-36d48179639fcf05a250ed973eaebfa3d4348a25.tar.bz2
Simplify krb5int_get_error (and fix a cast-qual warning) by not
worrying so much about system errors longer than 1K. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@23118 dc483132-0cff-0310-8789-dd5450dbe970
-rw-r--r--src/util/support/errors.c31
1 files changed, 7 insertions, 24 deletions
diff --git a/src/util/support/errors.c b/src/util/support/errors.c
index 2671a45..967c57a 100644
--- a/src/util/support/errors.c
+++ b/src/util/support/errors.c
@@ -116,7 +116,7 @@ krb5int_vset_error_fl (struct errinfo *ep, long code,
const char *
krb5int_get_error (struct errinfo *ep, long code)
{
- char *r, *r2;
+ const char *r, *r2;
if (code == ep->code && ep->msg) {
r = strdup(ep->msg);
if (r == NULL) {
@@ -153,41 +153,24 @@ krb5int_get_error (struct errinfo *ep, long code)
if (code < 0)
goto format_number;
#ifdef HAVE_STRERROR_R
- if (strerror_r (code, ep->scratch_buf, sizeof(ep->scratch_buf)) == 0) {
+ if (strerror_r(code, ep->scratch_buf, sizeof(ep->scratch_buf)) == 0) {
char *p = strdup(ep->scratch_buf);
if (p)
return p;
return ep->scratch_buf;
}
- /* If strerror_r didn't work with the 1K buffer, we can try a
- really big one. This seems kind of gratuitous though. */
-#define BIG_ERR_BUFSIZ 8192
- r = malloc(BIG_ERR_BUFSIZ);
- if (r) {
- if (strerror_r (code, r, BIG_ERR_BUFSIZ) == 0) {
- r2 = realloc (r, 1 + strlen(r));
- if (r2)
- return r2;
- return r;
- }
- free (r);
- }
#endif
- r = strerror (code);
+ r = strerror(code);
if (r) {
- if (strlen (r) < sizeof (ep->scratch_buf)
- || (r2 = strdup (r)) == NULL) {
- strncpy (ep->scratch_buf, r, sizeof(ep->scratch_buf));
- return ep->scratch_buf;
- } else
- return r2;
+ strlcpy(ep->scratch_buf, r, sizeof(ep->scratch_buf));
+ return ep->scratch_buf;
}
format_number:
snprintf (ep->scratch_buf, sizeof(ep->scratch_buf),
_("error %ld"), code);
return ep->scratch_buf;
}
- r = (char *) fptr(code);
+ r = fptr(code);
if (r == NULL) {
unlock();
goto format_number;
@@ -195,7 +178,7 @@ krb5int_get_error (struct errinfo *ep, long code)
r2 = strdup(r);
if (r2 == NULL) {
- strncpy(ep->scratch_buf, r, sizeof(ep->scratch_buf));
+ strlcpy(ep->scratch_buf, r, sizeof(ep->scratch_buf));
unlock();
return ep->scratch_buf;
} else {