Browse files

libfdisk: don't re-allocate range string in Ask API

Signed-off-by: Karel Zak <kzak@redhat.com>
  • Loading branch information...
1 parent 4fb18cd commit 5673f30de61598def3f50c4285e09e70f5706d48 @karelzak committed May 9, 2013
Showing with 4 additions and 11 deletions.
  1. +3 −10 libfdisk/src/ask.c
  2. +1 −1 libfdisk/src/fdiskP.h
View
13 libfdisk/src/ask.c
@@ -13,15 +13,6 @@ void fdisk_reset_ask(struct fdisk_ask *ask)
assert(ask);
free(ask->query);
- switch (ask->type) {
- case FDISK_ASKTYPE_OFFSET:
- case FDISK_ASKTYPE_NUMBER:
- free(ask->data.num.range);
- break;
- default:
- break;
- }
-
memset(ask, 0, sizeof(*ask));
}
@@ -90,7 +81,9 @@ const char *fdisk_ask_number_get_range(struct fdisk_ask *ask)
int fdisk_ask_number_set_range(struct fdisk_ask *ask, const char *range)
{
assert(ask);
- return !strdup_to_struct_member(ask, data.num.range, range) ? -ENOMEM : 0;
+ assert(is_number_ask(ask));
+ ask->data.num.range = range;
+ return 0;
}
uint64_t fdisk_ask_number_get_default(struct fdisk_ask *ask)
View
2 libfdisk/src/fdiskP.h
@@ -225,7 +225,7 @@ struct fdisk_ask {
uint64_t result;
uint64_t base; /* for relative results */
uint64_t unit; /* unit for offsets */
- char *range; /* by library generated list */
+ const char *range; /* by library generated list */
unsigned int relative:1;
} num;
/* FDISK_ASKTYPE_{WARN,WARNX,..} */

0 comments on commit 5673f30

Please sign in to comment.