Coverage Report

Created: 2026-05-30 06:07

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/hdf5/src/H5Obtreek.c
Line
Count
Source
1
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
 * Copyright by The HDF Group.                                               *
3
 * All rights reserved.                                                      *
4
 *                                                                           *
5
 * This file is part of HDF5.  The full HDF5 copyright notice, including     *
6
 * terms governing use, modification, and redistribution, is contained in    *
7
 * the LICENSE file, which can be found at the root of the source code       *
8
 * distribution tree, or in https://www.hdfgroup.org/licenses.               *
9
 * If you do not have access to either file, you may request a copy from     *
10
 * help@hdfgroup.org.                                                        *
11
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12
13
/*
14
 * Purpose: A message holding non-default v1 B-tree 'K' value
15
 *              information in the superblock extension.
16
 */
17
18
#include "H5Omodule.h" /* This source code file is part of the H5O module */
19
20
#include "H5private.h"   /* Generic Functions     */
21
#include "H5Eprivate.h"  /* Error handling        */
22
#include "H5Opkg.h"      /* Object headers      */
23
#include "H5MMprivate.h" /* Memory management     */
24
25
static void  *H5O__btreek_decode(H5F_t *f, H5O_t *open_oh, unsigned mesg_flags, unsigned *ioflags,
26
                                 size_t p_size, const uint8_t *p);
27
static herr_t H5O__btreek_encode(H5F_t *f, bool disable_shared, size_t H5_ATTR_UNUSED p_size, uint8_t *p,
28
                                 const void *_mesg);
29
static void  *H5O__btreek_copy(const void *_mesg, void *_dest);
30
static size_t H5O__btreek_size(const H5F_t *f, bool disable_shared, const void *_mesg);
31
static herr_t H5O__btreek_debug(H5F_t *f, const void *_mesg, FILE *stream, int indent, int fwidth);
32
33
/* This message derives from H5O message class */
34
const H5O_msg_class_t H5O_MSG_BTREEK[1] = {{
35
    H5O_BTREEK_ID,          /*message id number                     */
36
    "v1 B-tree 'K' values", /*message name for debugging            */
37
    sizeof(H5O_btreek_t),   /*native message size                   */
38
    0,                      /* messages are shareable?               */
39
    H5O__btreek_decode,     /*decode message                        */
40
    H5O__btreek_encode,     /*encode message                        */
41
    H5O__btreek_copy,       /*copy the native value                 */
42
    H5O__btreek_size,       /*raw message size      */
43
    NULL,                   /*free internal memory      */
44
    NULL,                   /* free method        */
45
    NULL,                   /* file delete method     */
46
    NULL,                   /* link method        */
47
    NULL,                   /*set share method            */
48
    NULL,                   /*can share method            */
49
    NULL,                   /* pre copy native value to file  */
50
    NULL,                   /* copy native value to file    */
51
    NULL,                   /* post copy native value to file */
52
    NULL,                   /* get creation index           */
53
    NULL,                   /* set creation index           */
54
    H5O__btreek_debug       /*debug the message     */
55
}};
56
57
/* Current version of v1 B-tree 'K' value information */
58
6
#define H5O_BTREEK_VERSION 0
59
60
/*-------------------------------------------------------------------------
61
 * Function:    H5O__btreek_decode
62
 *
63
 * Purpose:     Decode a shared message table message and return a pointer
64
 *              to a newly allocated H5O_btreek_t struct.
65
 *
66
 * Return:      Success:    Pointer to new message in native struct
67
 *              Failure:    NULL
68
 *-------------------------------------------------------------------------
69
 */
70
static void *
71
H5O__btreek_decode(H5F_t H5_ATTR_NDEBUG_UNUSED *f, H5O_t H5_ATTR_UNUSED *open_oh,
72
                   unsigned H5_ATTR_UNUSED mesg_flags, unsigned H5_ATTR_UNUSED *ioflags, size_t p_size,
73
                   const uint8_t *p)
74
6
{
75
6
    const uint8_t *p_end     = p + p_size - 1; /* End of input buffer */
76
6
    H5O_btreek_t  *mesg      = NULL;           /* Native message */
77
6
    void          *ret_value = NULL;           /* Return value */
78
79
6
    FUNC_ENTER_PACKAGE
80
81
6
    assert(f);
82
6
    assert(p);
83
84
    /* Version of message */
85
6
    if (H5_IS_BUFFER_OVERFLOW(p, 1, p_end))
86
0
        HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL, "ran off end of input buffer while decoding");
87
6
    if (*p++ != H5O_BTREEK_VERSION)
88
0
        HGOTO_ERROR(H5E_OHDR, H5E_CANTLOAD, NULL, "bad version number for message");
89
90
    /* Allocate space for message */
91
6
    if (NULL == (mesg = (H5O_btreek_t *)H5MM_calloc(sizeof(H5O_btreek_t))))
92
0
        HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL, "memory allocation failed for v1 B-tree 'K' message");
93
94
    /* Retrieve non-default B-tree 'K' values */
95
6
    if (H5_IS_BUFFER_OVERFLOW(p, 2, p_end))
96
0
        HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL, "ran off end of input buffer while decoding");
97
6
    UINT16DECODE(p, mesg->btree_k[H5B_CHUNK_ID]);
98
6
    if (H5_IS_BUFFER_OVERFLOW(p, 2, p_end))
99
0
        HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL, "ran off end of input buffer while decoding");
100
6
    UINT16DECODE(p, mesg->btree_k[H5B_SNODE_ID]);
101
6
    if (H5_IS_BUFFER_OVERFLOW(p, 2, p_end))
102
0
        HGOTO_ERROR(H5E_OHDR, H5E_OVERFLOW, NULL, "ran off end of input buffer while decoding");
103
6
    UINT16DECODE(p, mesg->sym_leaf_k);
104
105
    /* Set return value */
106
6
    ret_value = (void *)mesg;
107
108
6
done:
109
6
    if (NULL == ret_value)
110
0
        H5MM_free(mesg);
111
6
    FUNC_LEAVE_NOAPI(ret_value)
112
6
} /* end H5O__btreek_decode() */
113
114
/*-------------------------------------------------------------------------
115
 * Function:  H5O__btreek_encode
116
 *
117
 * Purpose: Encode a v1 B-tree 'K' value message.
118
 *
119
 * Return:  Non-negative on success/Negative on failure
120
 *
121
 *-------------------------------------------------------------------------
122
 */
123
static herr_t
124
H5O__btreek_encode(H5F_t H5_ATTR_UNUSED *f, bool H5_ATTR_UNUSED disable_shared, size_t H5_ATTR_UNUSED p_size,
125
                   uint8_t *p, const void *_mesg)
126
0
{
127
0
    const H5O_btreek_t *mesg = (const H5O_btreek_t *)_mesg;
128
129
0
    FUNC_ENTER_PACKAGE_NOERR
130
131
    /* Sanity check */
132
0
    assert(f);
133
0
    assert(p);
134
0
    assert(mesg);
135
136
    /* Store version and non-default v1 B-tree 'K' values */
137
0
    *p++ = H5O_BTREEK_VERSION;
138
0
    UINT16ENCODE(p, mesg->btree_k[H5B_CHUNK_ID]);
139
0
    UINT16ENCODE(p, mesg->btree_k[H5B_SNODE_ID]);
140
0
    UINT16ENCODE(p, mesg->sym_leaf_k);
141
142
0
    FUNC_LEAVE_NOAPI(SUCCEED)
143
0
} /* end H5O__btreek_encode() */
144
145
/*-------------------------------------------------------------------------
146
 * Function:  H5O__btreek_copy
147
 *
148
 * Purpose: Copies a message from _MESG to _DEST, allocating _DEST if
149
 *    necessary.
150
 *
151
 * Return:  Success:  Ptr to _DEST
152
 *    Failure:  NULL
153
 *
154
 *-------------------------------------------------------------------------
155
 */
156
static void *
157
H5O__btreek_copy(const void *_mesg, void *_dest)
158
6
{
159
6
    const H5O_btreek_t *mesg      = (const H5O_btreek_t *)_mesg;
160
6
    H5O_btreek_t       *dest      = (H5O_btreek_t *)_dest;
161
6
    void               *ret_value = NULL; /* Return value */
162
163
6
    FUNC_ENTER_PACKAGE
164
165
    /* Sanity check */
166
6
    assert(mesg);
167
168
6
    if (!dest && NULL == (dest = (H5O_btreek_t *)H5MM_malloc(sizeof(H5O_btreek_t))))
169
0
        HGOTO_ERROR(H5E_RESOURCE, H5E_NOSPACE, NULL,
170
6
                    "memory allocation failed for shared message table message");
171
172
    /* All this message requires is a shallow copy */
173
6
    *dest = *mesg;
174
175
    /* Set return value */
176
6
    ret_value = dest;
177
178
6
done:
179
6
    FUNC_LEAVE_NOAPI(ret_value)
180
6
} /* end H5O__btreek_copy() */
181
182
/*-------------------------------------------------------------------------
183
 * Function:  H5O__btreek_size
184
 *
185
 * Purpose: Returns the size of the raw message in bytes not counting the
186
 *    message type or size fields, but only the data fields.
187
 *
188
 * Return:  Success:  Message data size in bytes w/o alignment.
189
 *    Failure:  0
190
 *
191
 *-------------------------------------------------------------------------
192
 */
193
static size_t
194
H5O__btreek_size(const H5F_t H5_ATTR_UNUSED *f, bool H5_ATTR_UNUSED disable_shared,
195
                 const void H5_ATTR_UNUSED *_mesg)
196
0
{
197
0
    size_t ret_value = 0;
198
199
0
    FUNC_ENTER_PACKAGE_NOERR
200
201
    /* Sanity check */
202
0
    assert(f);
203
204
0
    ret_value = 1 + /* Version number */
205
0
                2 + /* Chunked storage internal B-tree 'K' value */
206
0
                2 + /* Symbol table node internal B-tree 'K' value */
207
0
                2;  /* Symbol table node leaf 'K' value */
208
209
0
    FUNC_LEAVE_NOAPI(ret_value)
210
0
} /* end H5O__btreek_size() */
211
212
/*-------------------------------------------------------------------------
213
 * Function:  H5O__btreek_debug
214
 *
215
 * Purpose: Prints debugging info for the message.
216
 *
217
 * Return:  Non-negative on success/Negative on failure
218
 *
219
 *-------------------------------------------------------------------------
220
 */
221
static herr_t
222
H5O__btreek_debug(H5F_t H5_ATTR_UNUSED *f, const void *_mesg, FILE *stream, int indent, int fwidth)
223
0
{
224
0
    const H5O_btreek_t *mesg = (const H5O_btreek_t *)_mesg;
225
226
0
    FUNC_ENTER_PACKAGE_NOERR
227
228
    /* Sanity check */
229
0
    assert(f);
230
0
    assert(mesg);
231
0
    assert(stream);
232
0
    assert(indent >= 0);
233
0
    assert(fwidth >= 0);
234
235
0
    fprintf(stream, "%*s%-*s %u\n", indent, "", fwidth,
236
0
            "Chunked storage internal B-tree 'K' value:", mesg->btree_k[H5B_CHUNK_ID]);
237
0
    fprintf(stream, "%*s%-*s %u\n", indent, "", fwidth,
238
0
            "Symbol table node internal B-tree 'K' value:", mesg->btree_k[H5B_SNODE_ID]);
239
0
    fprintf(stream, "%*s%-*s %u\n", indent, "", fwidth,
240
0
            "Symbol table node leaf 'K' value:", mesg->sym_leaf_k);
241
242
0
    FUNC_LEAVE_NOAPI(SUCCEED)
243
0
} /* end H5O__btreek_debug() */