Skip to content

Cannot distinguish between no-op insert and memory error #20

@scossu

Description

@scossu

I preface that I'm quite new to C so this may be completely off. However, in:

c-algorithms/src/set.c

Lines 256 to 275 in 5b0555f

if (set->equal_func(data, rover->data) != 0) {
/* This data is already in the set */
return 0;
}
rover = rover->next;
}
/* Not in the set. We must add a new entry. */
/* Make a new entry for this data */
newentry = (SetEntry *) malloc(sizeof(SetEntry));
if (newentry == NULL) {
return 0;
}

the 0 return value is used both for an operation that does not change the state of a set (because the value already exists), which may or may not be an issue, and a memory error, which is more likely to be an issue, and of a different type.

Shall the former not use a kind of custom error code, and the latter an ENOMEM according to https://www.gnu.org/software/libc/manual/html_node/Error-Codes.html ?

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions