summaryrefslogtreecommitdiffstats
path: root/core/dive.c
diff options
context:
space:
mode:
Diffstat (limited to 'core/dive.c')
-rw-r--r--core/dive.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/core/dive.c b/core/dive.c
index b82970862..14ab13f95 100644
--- a/core/dive.c
+++ b/core/dive.c
@@ -649,6 +649,15 @@ struct dive *clone_dive(struct dive *s)
if (what._component) \
d->_component = copy_string(s->_component)
+void copy_weights(const struct dive *s, struct dive *d)
+{
+ for (int i = 0; i < MAX_WEIGHTSYSTEMS; i++) {
+ free((void *)d->weightsystem[i].description);
+ d->weightsystem[i] = s->weightsystem[i];
+ d->weightsystem[i].description = copy_string(s->weightsystem[i].description);
+ }
+}
+
// copy elements, depending on bits in what that are set
void selective_copy_dive(const struct dive *s, struct dive *d, struct dive_components what, bool clear)
{
@@ -671,11 +680,7 @@ void selective_copy_dive(const struct dive *s, struct dive *d, struct dive_compo
if (what.cylinders)
copy_cylinders(s, d, false);
if (what.weights)
- for (int i = 0; i < MAX_WEIGHTSYSTEMS; i++) {
- free((void *)d->weightsystem[i].description);
- d->weightsystem[i] = s->weightsystem[i];
- d->weightsystem[i].description = copy_string(s->weightsystem[i].description);
- }
+ copy_weights(s, d);
}
#undef CONDITIONAL_COPY_STRING