Skip to content

[*] Concerns about safety, errors handling and inconsistencies #4751

@raysan5

Description

@raysan5

This issue is related to a reddit post about errors handling and inconsistencies.

raylib original approach was a hard focused on simplicity, trying to avoid any extra-code that could pollute the functions, leaving the security data checks to the users and expecting the data to be provided to most functions to be valid data.

But raylib has been +11 years in development and in that time some data validation checks have been added here and there resulting in some inconsistencies... and polluting the functions code with some things I originally tried to avoid (i.e early-returns).

Still, I tried to follow some principles in the library:

  • Users are the owners of data and valid data should be provided to raylib functions.
  • raylib does not use assert() or exit().
  • In case of issues with data, priority is logging a warning message and trying to return gracefully (with valid default data or at least something to be validated at user side - i.e. zero-initialized struct)
  • raylib does not (usually) use error return codes. (But lately some were added to file-system functions)
  • raylib text functions always expect \0 terminated strings, it's up to the user to make sure that happens.
  • raylib does not validate memory allocations returned pointers, the chances for a failure on memory allocation are extremely low but, in any case, users can define their own allocator macros.
  • In raylib I tried to minimize early returns from functions
  • In case some function return an error-code, I prefer to accumulate it into a result variable and use it for checking.

This issue is open to analyze if there could be some of those tentative rules not applied in some functions or if there are some inconsistencies.

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