svn rev #23118: trunk/src/util/support/

ghudson@MIT.EDU ghudson at MIT.EDU
Sun Nov 1 17:32:47 EST 2009


http://src.mit.edu/fisheye/changelog/krb5/?cs=23118
Commit By: ghudson
Log Message:
Simplify krb5int_get_error (and fix a cast-qual warning) by not
worrying so much about system errors longer than 1K.



Changed Files:
U   trunk/src/util/support/errors.c
Modified: trunk/src/util/support/errors.c
===================================================================
--- trunk/src/util/support/errors.c	2009-11-01 22:14:25 UTC (rev 23117)
+++ trunk/src/util/support/errors.c	2009-11-01 22:32:47 UTC (rev 23118)
@@ -116,7 +116,7 @@
 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 @@
 	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 @@
 
     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 {




More information about the cvs-krb5 mailing list