Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common/hostlist: update to latest from lsd-tools #159

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 20 additions & 18 deletions src/common/hostlist.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*****************************************************************************\
* $LSDId: hostlist.c 11882 2012-10-03 17:31:41Z grondo $
* $LSDId: commit c08d251f3cc9b1a5b69a268f952d64f990366835 $
*****************************************************************************
* Copyright (C) 2002 The Regents of the University of California.
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
Expand Down Expand Up @@ -379,7 +379,7 @@ static char * _next_tok(char *sep, char **str)
tok = *str;

while ( **str != '\0' &&
(level != 0 || strchr(sep, **str) == NULL) ) {
(level != 0 || strchr(sep, **str) == NULL) ) {
if ( **str == '[' ) level++;
else if ( **str == ']' ) level--;
(*str)++;
Expand Down Expand Up @@ -1063,7 +1063,7 @@ static hostlist_t hostlist_new(void)
if (!new)
goto fail1;

assert(new->magic = HOSTLIST_MAGIC);
assert((new->magic = HOSTLIST_MAGIC));
mutex_init(&new->mutex);

new->hr = (hostrange_t *) malloc(HOSTLIST_CHUNK * sizeof(hostrange_t));
Expand Down Expand Up @@ -1099,7 +1099,7 @@ static int hostlist_resize(hostlist_t hl, size_t newsize)
int i;
size_t oldsize;
assert(hl != NULL);
assert(hl->magic == HOSTLIST_MAGIC);
assert((hl->magic == HOSTLIST_MAGIC));
oldsize = hl->size;
hl->size = newsize;
hl->hr = realloc((void *) hl->hr, hl->size*sizeof(hostrange_t));
Expand Down Expand Up @@ -1186,7 +1186,7 @@ static int hostlist_insert_range(hostlist_t hl, hostrange_t hr, int n)
hostlist_iterator_t hli;

assert(hl != NULL);
assert(hl->magic == HOSTLIST_MAGIC);
assert((hl->magic == HOSTLIST_MAGIC));
assert(hr != NULL);

if (n > hl->nranges)
Expand Down Expand Up @@ -1225,7 +1225,7 @@ static void hostlist_delete_range(hostlist_t hl, int n)
hostrange_t old;

assert(hl != NULL);
assert(hl->magic == HOSTLIST_MAGIC);
assert((hl->magic == HOSTLIST_MAGIC));
assert(n < hl->nranges && n >= 0);

old = hl->hr[n];
Expand Down Expand Up @@ -1279,7 +1279,7 @@ hostlist_t _hostlist_create(const char *hostlist, char *sep, char *r_op)
/* find end of alpha part
* do this by finding last occurence of range_op in str */
pos = strlen(tok) - 1;
if (strstr(tok, r_op) != '\0') {
if (strstr(tok, r_op) != NULL) {
while (pos >= 0 && (char) tok[pos] != range_op)
pos--;
}
Expand Down Expand Up @@ -1512,7 +1512,7 @@ _hostlist_create_bracketed(const char *hostlist, char *sep, char *r_op)
}

while ((tok = _next_tok(sep, &str)) != NULL) {
strncpy(cur_tok, tok, 1023);
strncpy(cur_tok, tok, sizeof (cur_tok) - 1);

if ((p = strchr(tok, '[')) != NULL) {
char *q, *prefix = tok;
Expand All @@ -1529,17 +1529,20 @@ _hostlist_create_bracketed(const char *hostlist, char *sep, char *r_op)
else
_push_range_list(new, prefix, ranges, nr);

} else /* Error: brackets must be balanced */
goto error_unmatched;

} else
hostlist_push_host(new, cur_tok);

} else
} else if (strchr(tok, ']')) /* Error: brackets must be balanced */
goto error_unmatched;
else /* Ok: No brackets found, single host */
hostlist_push_host(new, cur_tok);
}

free(orig);
return new;

error_unmatched:
errno = EINVAL;
error:
err = errno;
hostlist_destroy(new);
Expand Down Expand Up @@ -1595,7 +1598,7 @@ void hostlist_destroy(hostlist_t hl)
for (i = 0; i < hl->nranges; i++)
hostrange_destroy(hl->hr[i]);
free(hl->hr);
assert(hl->magic = 0x1);
assert((hl->magic = 0x1));
UNLOCK_HOSTLIST(hl);
mutex_destroy(&hl->mutex);
free(hl);
Expand Down Expand Up @@ -2215,7 +2218,7 @@ static hostlist_iterator_t hostlist_iterator_new(void)
i->idx = 0;
i->depth = -1;
i->next = i;
assert(i->magic = HOSTLIST_MAGIC);
assert((i->magic = HOSTLIST_MAGIC));
return i;
}

Expand Down Expand Up @@ -2266,7 +2269,7 @@ void hostlist_iterator_destroy(hostlist_iterator_t i)
}
}
UNLOCK_HOSTLIST(i->hl);
assert(i->magic = 0x1);
assert((i->magic = 0x1));
free(i);
}

Expand All @@ -2278,12 +2281,11 @@ static void _iterator_advance(hostlist_iterator_t i)
return;
if (++(i->depth) > (i->hr->hi - i->hr->lo)) {
i->depth = 0;
if (i->idx >= (i->hl->size - 1)) {
++i->idx;
if (++i->idx >= i->hl->size) {
i->hr = NULL;
return;
}
i->hr = i->hl->hr[++i->idx];
i->hr = i->hl->hr[i->idx];
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/common/hostlist.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/*****************************************************************************\
* $Id$
*****************************************************************************
* $LSDId: hostlist.h 7428 2008-05-23 16:08:31Z grondo $
* $LSDId: commit c08d251f3cc9b1a5b69a268f952d64f990366835 $
*****************************************************************************
* Copyright (C) 2002 The Regents of the University of California.
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
Expand Down
Loading