From: Tom Yu Date: Thu, 25 Jun 2015 23:31:53 +0000 (-0400) Subject: Deindent krb5_string_to_keysalts X-Git-Tag: krb5-1.14-alpha1~84 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e110ce6ed19f5349e304e826e6b8066312c6c15c;p=thirdparty%2Fkrb5.git Deindent krb5_string_to_keysalts Remove a level of indentation for the list-appending part of the krb5_string_to_keysalts() loop body by consolidating the strtok_r() calls into the controlling expreession of the loop. --- diff --git a/src/lib/kadm5/str_conv.c b/src/lib/kadm5/str_conv.c index c28a1e9324..30c395101f 100644 --- a/src/lib/kadm5/str_conv.c +++ b/src/lib/kadm5/str_conv.c @@ -279,7 +279,7 @@ krb5_string_to_keysalts(const char *string, const char *tupleseps, const char *ksaltseps, krb5_boolean dups, krb5_key_salt_tuple **ksaltp, krb5_int32 *nksaltp) { - char *p, *ksp; + char *copy, *p, *ksp; char *tlasts = NULL; const char *tseps = (tupleseps != NULL) ? tupleseps : default_tupleseps; krb5_int32 nksalts = 0; @@ -290,35 +290,36 @@ krb5_string_to_keysalts(const char *string, const char *tupleseps, *ksaltp = NULL; *nksaltp = 0; - p = strdup(string); + p = copy = strdup(string); if (p == NULL) return ENOMEM; - ksp = strtok_r(p, tseps, &tlasts); - while (ksp != NULL) { + while ((ksp = strtok_r(p, tseps, &tlasts)) != NULL) { + /* Pass a null pointer to subsequent calls to strtok_r(). */ + p = NULL; ret = string_to_keysalt(ksp, ksaltseps, &etype, &stype); if (ret) goto cleanup; /* Ignore duplicate keysalts if caller asks. */ - if (dups || !krb5_keysalt_is_present(ksalts, nksalts, etype, stype)) { - ksalts_new = realloc(ksalts, (nksalts + 1) * sizeof(*ksalts)); - if (ksalts_new == NULL) { - ret = ENOMEM; - goto cleanup; - } - ksalts = ksalts_new; - ksalts[nksalts].ks_enctype = etype; - ksalts[nksalts].ks_salttype = stype; - nksalts++; + if (!dups && krb5_keysalt_is_present(ksalts, nksalts, etype, stype)) + continue; + + ksalts_new = realloc(ksalts, (nksalts + 1) * sizeof(*ksalts)); + if (ksalts_new == NULL) { + ret = ENOMEM; + goto cleanup; } - ksp = strtok_r(NULL, tseps, &tlasts); + ksalts = ksalts_new; + ksalts[nksalts].ks_enctype = etype; + ksalts[nksalts].ks_salttype = stype; + nksalts++; } *ksaltp = ksalts; *nksaltp = nksalts; cleanup: if (ret) free(ksalts); - free(p); + free(copy); return ret; }