Skip to content

Migrate codebase to use S2N_RESULT by default #2425

Open
@camshaft

Description

@camshaft

Problem:

Right now, most of the codebase uses int as the function return value. As documented in s2n_result.c, this has a few problems:

  • GUARDing in a function that returns integer types
  • GUARDing a function that returns integer type
  • Forgetting to GUARD a function that returned an error signal

Solution:

The majority of the codebase should return S2N_RESULT. This is statically checked to ensure:

  • The code cannot GUARD in a function that returns integer types:

    uint8_t s2n_answer_to_the_ultimate_question() {
      GUARD(s2n_sleep_for_years(7500000)); /* <- Won't compile since this function doesn't return an S2N_RESULT */
      return 42;
    }
  • The code cannot GUARD a function that returns integer types:

    S2N_RESULT s2n_deep_thought() {
      GUARD(s2n_answer_to_the_ultimate_question()); /* <- Won't compile since the function being called doesn't return an S2N_RESULT */
      return S2N_RESULT_OK;
    }
  • The code cannot ignore the return value of a function

    uint8_t s2n_answer_to_the_ultimate_question() {
      s2n_sleep_for_years(7500000); /* <- Won't compile since the function being called returns a `S2N_RESULT` isn't `GUARD`ed */
      return 42;
    }

Requirements / Acceptance Criteria:

The following tasks are implemented in a way that will make the transition as painless as possible, especially for any pending PRs.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions