Coverage Report

Created: 2026-01-10 06:23

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libgd/src/gdhelpers.c
Line
Count
Source
1
#ifdef HAVE_CONFIG_H
2
#include "config.h"
3
#endif
4
5
#include "gd.h"
6
#include "gdhelpers.h"
7
#include <stdlib.h>
8
#include <string.h>
9
10
#include <sys/types.h>
11
#include <ctype.h>
12
13
/* TBB: gd_strtok_r is not portable; provide an implementation */
14
15
0
#define SEP_TEST (separators[*((unsigned char *) s)])
16
17
char *
18
gd_strtok_r(char *s, const char *sep, char **state)
19
0
{
20
0
  char separators[256];
21
0
  char *result = 0;
22
0
  memset (separators, 0, sizeof (separators));
23
0
  while (*sep) {
24
0
    separators[*((const unsigned char *) sep)] = 1;
25
0
    sep++;
26
0
  }
27
0
  if (!s) {
28
    /* Pick up where we left off */
29
0
    s = *state;
30
0
  }
31
  /* 1. EOS */
32
0
  if (!(*s)) {
33
0
    *state = s;
34
0
    return 0;
35
0
  }
36
  /* 2. Leading separators, if any */
37
0
  if (SEP_TEST) {
38
0
    do {
39
0
      s++;
40
0
    } while (SEP_TEST);
41
    /* 2a. EOS after separators only */
42
0
    if (!(*s)) {
43
0
      *state = s;
44
0
      return 0;
45
0
    }
46
0
  }
47
  /* 3. A token */
48
0
  result = s;
49
0
  do {
50
    /* 3a. Token at end of string */
51
0
    if (!(*s)) {
52
0
      *state = s;
53
0
      return result;
54
0
    }
55
0
    s++;
56
0
  } while (!SEP_TEST);
57
  /* 4. Terminate token and skip trailing separators */
58
0
  *s = '\0';
59
0
  do {
60
0
    s++;
61
0
  } while (SEP_TEST);
62
  /* 5. Return token */
63
0
  *state = s;
64
0
  return result;
65
0
}
66
67
void * gdCalloc (size_t nmemb, size_t size)
68
57.6k
{
69
57.6k
  return calloc (nmemb, size);
70
57.6k
}
71
72
void *
73
gdMalloc (size_t size)
74
820
{
75
820
  return malloc (size);
76
820
}
77
78
void *
79
gdRealloc (void *ptr, size_t size)
80
0
{
81
0
  return realloc (ptr, size);
82
0
}
83
84
void *
85
gdReallocEx (void *ptr, size_t size)
86
0
{
87
0
  void *newPtr = gdRealloc (ptr, size);
88
0
  if (!newPtr && ptr)
89
0
    gdFree(ptr);
90
0
  return newPtr;
91
0
}
92
93
/*
94
  Function: gdFree
95
96
    Frees memory that has been allocated by libgd functions.
97
98
  Unless more specialized functions exists (for instance, <gdImageDestroy>),
99
  all memory that has been allocated by public libgd functions has to be
100
  freed by calling <gdFree>, and not by free(3), because libgd internally
101
  doesn't use alloc(3) and friends but rather its own allocation functions,
102
  which are, however, not publicly available.
103
104
  Parameters:
105
106
  ptr - Pointer to the memory space to free. If it is NULL, no operation is
107
      performed.
108
109
  Returns:
110
111
  Nothing.
112
*/
113
BGD_DECLARE(void) gdFree (void *ptr)
114
58.5k
{
115
58.5k
  free (ptr);
116
58.5k
}