Coverage Report

Created: 2026-01-13 07:09

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libesedb/libesedb/libesedb_page_value.c
Line
Count
Source
1
/*
2
 * Page value functions
3
 *
4
 * Copyright (C) 2009-2025, Joachim Metz <joachim.metz@gmail.com>
5
 *
6
 * Refer to AUTHORS for acknowledgements.
7
 *
8
 * This program is free software: you can redistribute it and/or modify
9
 * it under the terms of the GNU Lesser General Public License as published by
10
 * the Free Software Foundation, either version 3 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public License
19
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
20
 */
21
22
#include <common.h>
23
#include <memory.h>
24
#include <types.h>
25
26
#include "libesedb_libcerror.h"
27
#include "libesedb_page_value.h"
28
29
/* Creates a page value
30
 * Make sure the value page_value is referencing, is set to NULL
31
 * Returns 1 if successful or -1 on error
32
 */
33
int libesedb_page_value_initialize(
34
     libesedb_page_value_t **page_value,
35
     libcerror_error_t **error )
36
1.54M
{
37
1.54M
  static char *function = "libesedb_page_value_initialize";
38
39
1.54M
  if( page_value == NULL )
40
0
  {
41
0
    libcerror_error_set(
42
0
     error,
43
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
44
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
45
0
     "%s: invalid page value.",
46
0
     function );
47
48
0
    return( -1 );
49
0
  }
50
1.54M
  if( *page_value != NULL )
51
0
  {
52
0
    libcerror_error_set(
53
0
     error,
54
0
     LIBCERROR_ERROR_DOMAIN_RUNTIME,
55
0
     LIBCERROR_RUNTIME_ERROR_VALUE_ALREADY_SET,
56
0
     "%s: invalid page value value already set.",
57
0
     function );
58
59
0
    return( -1 );
60
0
  }
61
1.54M
  *page_value = memory_allocate_structure(
62
1.54M
                 libesedb_page_value_t );
63
64
1.54M
  if( *page_value == NULL )
65
0
  {
66
0
    libcerror_error_set(
67
0
     error,
68
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
69
0
     LIBCERROR_MEMORY_ERROR_INSUFFICIENT,
70
0
     "%s: unable to create page value.",
71
0
     function );
72
73
0
    goto on_error;
74
0
  }
75
1.54M
  if( memory_set(
76
1.54M
       *page_value,
77
1.54M
       0,
78
1.54M
       sizeof( libesedb_page_value_t ) ) == NULL )
79
0
  {
80
0
    libcerror_error_set(
81
0
     error,
82
0
     LIBCERROR_ERROR_DOMAIN_MEMORY,
83
0
     LIBCERROR_MEMORY_ERROR_SET_FAILED,
84
0
     "%s: unable to clear page value.",
85
0
     function );
86
87
0
    goto on_error;
88
0
  }
89
1.54M
  return( 1 );
90
91
0
on_error:
92
0
  if( *page_value != NULL )
93
0
  {
94
0
    memory_free(
95
0
     *page_value );
96
97
0
    *page_value = NULL;
98
0
  }
99
0
  return( -1 );
100
1.54M
}
101
102
/* Frees a page value
103
 * Returns 1 if successful or -1 on error
104
 */
105
int libesedb_page_value_free(
106
     libesedb_page_value_t **page_value,
107
     libcerror_error_t **error )
108
1.54M
{
109
1.54M
  static char *function = "libesedb_page_value_free";
110
111
1.54M
  if( page_value == NULL )
112
0
  {
113
0
    libcerror_error_set(
114
0
     error,
115
0
     LIBCERROR_ERROR_DOMAIN_ARGUMENTS,
116
0
     LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE,
117
0
     "%s: invalid page value.",
118
0
     function );
119
120
0
    return( -1 );
121
0
  }
122
1.54M
  if( *page_value != NULL )
123
1.54M
  {
124
    /* The data is referenced and freed elsewhere
125
     */
126
1.54M
    memory_free(
127
1.54M
     *page_value );
128
129
    *page_value = NULL;
130
1.54M
  }
131
1.54M
  return( 1 );
132
1.54M
}
133