krb5 commit: Deindent krb5_string_to_keysalts
Tom Yu
tlyu at mit.edu
Thu Jul 2 16:30:16 EDT 2015
https://github.com/krb5/krb5/commit/e110ce6ed19f5349e304e826e6b8066312c6c15c
commit e110ce6ed19f5349e304e826e6b8066312c6c15c
Author: Tom Yu <tlyu at mit.edu>
Date: Thu Jun 25 19:31:53 2015 -0400
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.
src/lib/kadm5/str_conv.c | 33 +++++++++++++++++----------------
1 files changed, 17 insertions(+), 16 deletions(-)
diff --git a/src/lib/kadm5/str_conv.c b/src/lib/kadm5/str_conv.c
index c28a1e9..30c3951 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;
}
More information about the cvs-krb5
mailing list