File: utility.h

package info (click to toggle)
cbmc 6.6.0-4
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 153,852 kB
  • sloc: cpp: 386,459; ansic: 114,466; java: 28,405; python: 6,003; yacc: 4,552; makefile: 4,041; lex: 2,487; xml: 2,388; sh: 2,050; perl: 557; pascal: 184; javascript: 163; ada: 36
file content (40 lines) | stat: -rw-r--r-- 697 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <stdbool.h>
#include <stdlib.h>

/* Function return code  */
#define S2N_SUCCESS 0
#define S2N_FAILURE -1

/* A value which indicates the outcome of a function */
typedef struct
{
  int __error_signal;
} s2n_result;

#define S2N_RESULT s2n_result
#define S2N_RESULT_OK ((s2n_result){S2N_SUCCESS})
#define S2N_RESULT_ERROR ((s2n_result){S2N_FAILURE})

bool s2n_result_is_ok(s2n_result result)
{
  return result.__error_signal == S2N_SUCCESS;
}

bool validity1(int *x)
{
  return (x > 0);
}

bool validity2(int *x)
{
  return (x == 0);
}

S2N_RESULT validity3(int *x)
{
  if(x == NULL)
    return S2N_RESULT_ERROR;
  if(!validity1(x))
    return S2N_RESULT_ERROR;
  return S2N_RESULT_OK;
}