Fixed a bug in AMresultFrom()
.
This commit is contained in:
parent
5c06a2e4b1
commit
62bf0f6030
2 changed files with 27 additions and 27 deletions
|
@ -530,8 +530,9 @@ pub unsafe extern "C" fn AMfree(result: *mut AMresult) {
|
|||
///
|
||||
/// \param[in] dest A pointer to an `AMresult` struct.
|
||||
/// \param[in] src A pointer to an `AMresult` struct.
|
||||
/// \return A pointer to an `AMresult` struct with copies of the items from both
|
||||
/// \p dest and \p src in their original order.
|
||||
/// \return A pointer to an `AMresult` struct with the items from \p dest in
|
||||
/// their original order followed by the items from \p src in their
|
||||
/// original order.
|
||||
/// \pre \p dest `!= NULL`
|
||||
/// \pre \p src `!= NULL`
|
||||
/// \warning The returned `AMresult` struct pointer must be passed to `AMfree()` in
|
||||
|
@ -626,13 +627,11 @@ pub unsafe extern "C" fn AMresultSize(result: *const AMresult) -> usize {
|
|||
use self::AMresult::*;
|
||||
|
||||
if let Some(result) = result.as_ref() {
|
||||
match result {
|
||||
Error(_) => 0,
|
||||
Items(items) => items.len(),
|
||||
if let Items(items) = result {
|
||||
return items.len();
|
||||
}
|
||||
} else {
|
||||
0
|
||||
}
|
||||
0
|
||||
}
|
||||
|
||||
/// \memberof AMresult
|
||||
|
|
|
@ -3,30 +3,31 @@
|
|||
#include <automerge-c/utils/result.h>
|
||||
|
||||
AMresult* AMresultFrom(int count, ...) {
|
||||
AMresult* result = NULL;
|
||||
bool is_error = false;
|
||||
AMresult* result = NULL;
|
||||
bool is_ok = true;
|
||||
va_list args;
|
||||
va_start(args, count);
|
||||
for (int i = 0; i != count; ++i) {
|
||||
AMresult* src = va_arg(args, AMresult*);
|
||||
AMresult* dest = result;
|
||||
if (!is_error && (AMresultStatus(src) == AM_STATUS_OK)) {
|
||||
if (dest) {
|
||||
result = AMresultCat(dest, src);
|
||||
AMfree(dest);
|
||||
AMfree(src);
|
||||
} else {
|
||||
result = src;
|
||||
}
|
||||
} else {
|
||||
is_error = true;
|
||||
AMfree(src);
|
||||
}
|
||||
AMresult* dest = result;
|
||||
is_ok = (AMresultStatus(src) == AM_STATUS_OK);
|
||||
if (is_ok) {
|
||||
if (dest) {
|
||||
result = AMresultCat(dest, src);
|
||||
is_ok = (AMresultStatus(result) == AM_STATUS_OK);
|
||||
AMfree(dest);
|
||||
AMfree(src);
|
||||
} else {
|
||||
result = src;
|
||||
}
|
||||
} else {
|
||||
AMfree(src);
|
||||
}
|
||||
}
|
||||
va_end(args);
|
||||
if (is_error) {
|
||||
AMfree(result);
|
||||
result = NULL;
|
||||
}
|
||||
return result;
|
||||
if (!is_ok) {
|
||||
AMfree(result);
|
||||
result = NULL;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue