I may have not yet shared my final version of the patch which gives
the user as much error message(s) that are extractable from both the
context and the return code:

$ diff -u error_string.c.orig error_string.c
--- error_string.c.orig 2017-07-11 07:14:16.000000000 +0200
+++ error_string.c      2017-10-05 21:04:50.064079947 +0200
@@ -234,8 +234,6 @@
         }
        HEIMDAL_MUTEX_unlock(&context->mutex);
 
-        if (str)
-            return str;
     }
     else
     {
@@ -249,10 +247,26 @@
     if (free_context)
         krb5_free_context(context);
 
-    if (cstr)
-        return strdup(cstr);
+    if (!cstr) {
+       if (cstr = error_message(code)) {
+           strlcpy(buf, cstr, sizeof(buf));
+           cstr = buf;
+       }
+    }
 
-    cstr = error_message(code);
+    if (str && !cstr)
+       return str;
+
+    if (str && cstr) {
+       if (strncmp(str, cstr, sizeof(buf)) == 0)
+           return str;
+       else {
+           strlcat(buf, ", ", sizeof(buf));
+           strlcat(buf,  str, sizeof(buf));
+           return strdup(cstr);
+       }
+    }
+
     if (cstr)
         return strdup(cstr);
 
So...whatyouthinkaboutthat? Yes, str*foo() in C is a pain.

Harald.

Reply via email to