• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

tbeu / matio / #1032

11 Apr 2026 09:35AM UTC coverage: 83.515%. Remained the same
#1032

push

travis-ci

tbeu
Add support for MCOS

As reported by https://github.com/tbeu/matio/issues/47, https://github.com/tbeu/matio/issues/77, https://github.com/tbeu/matio/issues/148, https://github.com/tbeu/matio/issues/263, https://github.com/tbeu/matio/issues/270, https://github.com/tbeu/matio/issues/272

1683 of 2152 new or added lines in 7 files covered. (78.21%)

1266 existing lines in 6 files now uncovered.

12959 of 15517 relevant lines covered (83.51%)

54004.6 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.45
/src/matvar_struct.c
1
/*
2
 * Copyright (c) 2015-2026, The matio contributors
3
 * Copyright (c) 2012-2014, Christopher C. Hulbert
4
 * All rights reserved.
5
 *
6
 * SPDX-License-Identifier: BSD-2-Clause
7
 */
8

9
#include "matio_private.h"
10
#include <stdlib.h>
11
#include <string.h>
12
#if defined(_MSC_VER) || defined(__MINGW32__)
13
#define strdup _strdup
14
#endif
15

16
static matvar_t *
17
VarCreateStruct(const char *name, int rank, const size_t *dims, const char *const *fields,
26✔
18
                unsigned nfields)
19
{
20
    size_t nelems = 1;
26✔
21
    int j;
26✔
22
    matvar_t *matvar;
26✔
23

24
    if ( NULL == dims )
26✔
25
        return NULL;
26

27
    matvar = Mat_VarCalloc();
26✔
28
    if ( NULL == matvar )
26✔
29
        return NULL;
30

31
    matvar->compression = MAT_COMPRESSION_NONE;
26✔
32
    if ( NULL != name )
26✔
33
        matvar->name = strdup(name);
26✔
34
    matvar->rank = rank;
26✔
35
    matvar->dims = (size_t *)malloc(matvar->rank * sizeof(*matvar->dims));
26✔
36
    for ( j = 0; j < matvar->rank; j++ ) {
80✔
37
        matvar->dims[j] = dims[j];
54✔
38
        nelems *= dims[j];
54✔
39
    }
40
    matvar->class_type = MAT_C_STRUCT;
26✔
41
    matvar->data_type = MAT_T_STRUCT;
26✔
42

43
    matvar->data_size = sizeof(matvar_t *);
26✔
44

45
    if ( nfields ) {
26✔
46
        matvar->internal->num_fields = nfields;
23✔
47
        matvar->internal->fieldnames =
23✔
48
            (char **)malloc(nfields * sizeof(*matvar->internal->fieldnames));
23✔
49
        if ( NULL == matvar->internal->fieldnames ) {
23✔
50
            Mat_VarFree(matvar);
×
51
            matvar = NULL;
×
52
        } else {
53
            size_t i;
54
            for ( i = 0; i < nfields; i++ ) {
84✔
55
                if ( NULL == fields[i] ) {
61✔
56
                    Mat_VarFree(matvar);
×
57
                    matvar = NULL;
×
58
                    break;
×
59
                } else {
60
                    matvar->internal->fieldnames[i] = strdup(fields[i]);
61✔
61
                }
62
            }
63
        }
64
        if ( NULL != matvar && nelems > 0 ) {
23✔
65
            size_t nelems_x_nfields;
22✔
66
            int err = Mul(&nelems_x_nfields, nelems, nfields);
22✔
67
            err |= Mul(&matvar->nbytes, nelems_x_nfields, matvar->data_size);
22✔
68
            if ( err ) {
22✔
69
                Mat_VarFree(matvar);
×
70
                return NULL;
×
71
            }
72
            matvar->data = calloc(nelems_x_nfields, matvar->data_size);
22✔
73
        }
74
    }
75

76
    return matvar;
77
}
78

79
/** @brief Creates a structure MATLAB variable with the given name and fields
80
 *
81
 * @ingroup MAT
82
 * @param name Name of the structure variable to create
83
 * @param rank Rank of the variable
84
 * @param dims array of dimensions of the variable of size rank
85
 * @param fields Array of @c nfields fieldnames
86
 * @param nfields Number of fields in the structure
87
 * @return Pointer to the new structure MATLAB variable on success, NULL on error
88
 */
89
matvar_t *
90
Mat_VarCreateStruct(const char *name, int rank, const size_t *dims, const char *const *fields,
×
91
                    unsigned nfields)
92
{
93
    return VarCreateStruct(name, rank, dims, fields, nfields);
×
94
}
95

96
/** @brief Creates a structure MATLAB variable with the given name and fields
97
 *
98
 * @ingroup MAT
99
 * @param name Name of the structure variable to create
100
 * @param rank Rank of the variable
101
 * @param dims array of dimensions of the variable of size rank
102
 * @param fields NULL-terminated array of fieldnames
103
 * @return Pointer to the new structure MATLAB variable on success, NULL on error
104
 */
105
matvar_t *
106
Mat_VarCreateStruct2(const char *name, int rank, const size_t *dims, const char *const *fields)
26✔
107
{
108
    unsigned count = 0;
26✔
109
    if ( NULL == fields )
26✔
110
        return VarCreateStruct(name, rank, dims, fields, count);
3✔
111

112
    while ( fields[count] ) {
84✔
113
        count++;
61✔
114
    }
115
    return VarCreateStruct(name, rank, dims, fields, count);
23✔
116
}
117

118
/** @brief Adds a field to a structure
119
 *
120
 * Adds the given field to the structure. fields should be an array of matvar_t
121
 * pointers of the same size as the structure (i.e. 1 field per structure
122
 * element).
123
 * @ingroup MAT
124
 * @param matvar Pointer to the Structure MAT variable
125
 * @param fieldname Name of field to be added
126
 * @retval 0 on success
127
 * @deprecated Use Mat_VarAddStructField2 instead.
128
 */
129
int
130
Mat_VarAddStructField(matvar_t *matvar, const char *fieldname)
2✔
131
{
132
    int err;
2✔
133
    int cnt = 0;
2✔
134
    size_t i, nfields, nelems = 1;
2✔
135
    matvar_t **new_data, **old_data;
2✔
136
    char **fieldnames;
2✔
137

138
    if ( matvar == NULL || fieldname == NULL )
2✔
139
        return -1;
140

141
    err = Mat_MulDims(matvar, &nelems);
2✔
142
    if ( err )
2✔
143
        return -1;
144

145
    nfields = matvar->internal->num_fields + 1;
2✔
146
    fieldnames = (char **)realloc(matvar->internal->fieldnames,
2✔
147
                                  nfields * sizeof(*matvar->internal->fieldnames));
148
    if ( NULL == fieldnames )
2✔
149
        return -1;
150
    matvar->internal->num_fields = nfields;
2✔
151
    matvar->internal->fieldnames = fieldnames;
2✔
152
    matvar->internal->fieldnames[nfields - 1] = strdup(fieldname);
2✔
153

154
    {
155
        size_t nelems_x_nfields;
2✔
156
        err = Mul(&nelems_x_nfields, nelems, nfields);
2✔
157
        err |= Mul(&matvar->nbytes, nelems_x_nfields, sizeof(*new_data));
2✔
158
        if ( err ) {
2✔
159
            matvar->nbytes = 0;
×
160
            return -1;
×
161
        }
162
    }
163
    new_data = (matvar_t **)malloc(matvar->nbytes);
2✔
164
    if ( new_data == NULL ) {
2✔
165
        matvar->nbytes = 0;
×
166
        return -1;
×
167
    }
168

169
    old_data = (matvar_t **)matvar->data;
2✔
170
    for ( i = 0; i < nelems; i++ ) {
6✔
171
        size_t f;
172
        for ( f = 0; f < nfields - 1; f++ )
6✔
173
            new_data[cnt++] = old_data[i * (nfields - 1) + f];
2✔
174
        new_data[cnt++] = NULL;
4✔
175
    }
176

177
    free(matvar->data);
2✔
178
    matvar->data = new_data;
2✔
179

180
    return 0;
2✔
181
}
182

183
/** @brief Returns the number of fields in a structure variable
184
 *
185
 * Returns the number of fields in the given structure.
186
 * @ingroup MAT
187
 * @param matvar Structure matlab variable
188
 * @returns Number of fields
189
 */
190
unsigned
191
Mat_VarGetNumberOfFields(const matvar_t *matvar)
109✔
192
{
193
    int nfields;
109✔
194
    if ( matvar == NULL ||
109✔
195
         (matvar->class_type != MAT_C_STRUCT && matvar->class_type != MAT_C_OBJECT) ||
108✔
196
         NULL == matvar->internal ) {
108✔
197
        nfields = 0;
198
    } else {
199
        nfields = matvar->internal->num_fields;
108✔
200
    }
201
    return nfields;
109✔
202
}
203

204
/** @brief Returns the fieldnames of a structure variable
205
 *
206
 * Returns the fieldnames for the given structure. The returned pointers are
207
 * internal to the structure and should not be free'd.
208
 * @ingroup MAT
209
 * @param matvar Structure matlab variable
210
 * @returns Array of fieldnames
211
 */
212
char *const *
213
Mat_VarGetStructFieldnames(const matvar_t *matvar)
24✔
214
{
215
    if ( matvar == NULL ||
24✔
216
         (matvar->class_type != MAT_C_STRUCT && matvar->class_type != MAT_C_OBJECT) ||
23✔
217
         NULL == matvar->internal ) {
23✔
218
        return NULL;
219
    } else {
220
        return matvar->internal->fieldnames;
23✔
221
    }
222
}
223

224
/** @brief Finds a field of a structure by the field's index
225
 *
226
 * Returns a pointer to the structure field at the given 0-relative index.
227
 * @ingroup MAT
228
 * @param matvar Pointer to the Structure MAT variable
229
 * @param field_index 0-relative index of the field.
230
 * @param index linear index of the structure array
231
 * @return Pointer to the structure field on success, NULL on error
232
 */
233
matvar_t *
234
Mat_VarGetStructFieldByIndex(const matvar_t *matvar, size_t field_index, size_t index)
800✔
235
{
236
    int err;
800✔
237
    matvar_t *field = NULL;
800✔
238
    size_t nelems = 1, nfields;
800✔
239

240
    if ( matvar == NULL || matvar->data == NULL ||
800✔
241
         (matvar->class_type != MAT_C_STRUCT && matvar->class_type != MAT_C_OBJECT) ||
800✔
242
         matvar->data_size == 0 )
800✔
243
        return NULL;
244

245
    err = Mat_MulDims(matvar, &nelems);
800✔
246
    if ( err )
800✔
247
        return NULL;
248

249
    nfields = matvar->internal->num_fields;
800✔
250

251
    if ( nelems > 0 && index >= nelems ) {
800✔
UNCOV
252
        Mat_Critical("Mat_VarGetStructField: structure index out of bounds");
×
253
    } else if ( nfields > 0 ) {
800✔
254
        if ( field_index > nfields ) {
800✔
UNCOV
255
            Mat_Critical("Mat_VarGetStructField: field index out of bounds");
×
256
        } else {
257
            field = *((matvar_t **)matvar->data + index * nfields + field_index);
800✔
258
        }
259
    }
260

261
    return field;
262
}
263

264
/** @brief Finds a field of a structure by the field's name
265
 *
266
 * Returns a pointer to the structure field at the given 0-relative index.
267
 * @ingroup MAT
268
 * @param matvar Pointer to the Structure MAT variable
269
 * @param field_name Name of the structure field
270
 * @param index linear index of the structure array
271
 * @return Pointer to the structure field on success, NULL on error
272
 */
273
matvar_t *
274
Mat_VarGetStructFieldByName(const matvar_t *matvar, const char *field_name, size_t index)
808✔
275
{
276
    int i, nfields, field_index, err;
808✔
277
    matvar_t *field = NULL;
808✔
278
    size_t nelems = 1;
808✔
279

280
    if ( matvar == NULL || matvar->data == NULL ||
808✔
281
         (matvar->class_type != MAT_C_STRUCT && matvar->class_type != MAT_C_OBJECT) ||
806✔
282
         matvar->data_size == 0 )
806✔
283
        return NULL;
284

285
    err = Mat_MulDims(matvar, &nelems);
806✔
286
    if ( err )
806✔
287
        return NULL;
288

289
    nfields = matvar->internal->num_fields;
806✔
290
    field_index = -1;
806✔
291
    for ( i = 0; i < nfields; i++ ) {
1,810✔
292
        if ( !strcmp(matvar->internal->fieldnames[i], field_name) ) {
1,786✔
293
            field_index = i;
294
            break;
295
        }
296
    }
297

298
    if ( index >= nelems ) {
806✔
UNCOV
299
        Mat_Critical("Mat_VarGetStructField: structure index out of bounds");
×
300
    } else if ( field_index >= 0 ) {
806✔
301
        field = *((matvar_t **)matvar->data + index * nfields + field_index);
782✔
302
    }
303

304
    return field;
305
}
306

307
/** @brief Finds a field of a structure
308
 *
309
 * Returns a pointer to the structure field at the given 0-relative index.
310
 * @ingroup MAT
311
 * @param matvar Pointer to the Structure MAT variable
312
 * @param name_or_index Name of the field, or the 1-relative index of the field
313
 * If the index is used, it should be the address of an integer variable whose
314
 * value is the index number.
315
 * @param opt MAT_BY_NAME if the name_or_index is the name or MAT_BY_INDEX if
316
 *            the index was passed.
317
 * @param index linear index of the structure to find the field of
318
 * @return Pointer to the Structure Field on success, NULL on error
319
 */
320
matvar_t *
321
Mat_VarGetStructField(const matvar_t *matvar, void *name_or_index, int opt, int index)
801✔
322
{
323
    int err, nfields;
801✔
324
    matvar_t *field = NULL;
801✔
325
    size_t nelems = 1;
801✔
326

327
    err = Mat_MulDims(matvar, &nelems);
801✔
328
    nfields = matvar->internal->num_fields;
801✔
329
    if ( index < 0 || (nelems > 0 && (size_t)index >= nelems) )
801✔
330
        err = 1;
331
    else if ( nfields < 1 )
801✔
UNCOV
332
        err = 1;
×
333

334
    if ( !err && (opt == MAT_BY_INDEX) ) {
801✔
335
        size_t field_index = *(int *)name_or_index;
800✔
336
        if ( field_index > 0 )
800✔
337
            field = Mat_VarGetStructFieldByIndex(matvar, field_index - 1, index);
800✔
338
    } else if ( !err && (opt == MAT_BY_NAME) ) {
1✔
339
        field = Mat_VarGetStructFieldByName(matvar, (const char *)name_or_index, index);
1✔
340
    }
341

342
    return field;
801✔
343
}
344

345
/** @brief Indexes a structure
346
 *
347
 * Finds structures of a structure array given a start, stride, and edge for
348
 * each dimension.  The structures are placed in a new structure array.  If
349
 * copy_fields is non-zero, the indexed structures are copied and should be
350
 * freed, but if copy_fields is zero, the indexed structures are pointers to
351
 * the original, but should still be freed. The structures have a flag set
352
 * so that the structure fields are not freed.
353
 *
354
 * Note that this function is limited to structure arrays with a rank less than
355
 * 10.
356
 *
357
 * @ingroup MAT
358
 * @param matvar Structure matlab variable
359
 * @param start vector of length rank with 0-relative starting coordinates for
360
 *              each dimension.
361
 * @param stride vector of length rank with strides for each dimension.
362
 * @param edge vector of length rank with the number of elements to read in
363
 *              each dimension.
364
 * @param copy_fields 1 to copy the fields, 0 to just set pointers to them.
365
 * @returns A new structure array with fields indexed from @c matvar.
366
 */
367
matvar_t *
368
Mat_VarGetStructs(const matvar_t *matvar, const int *start, const int *stride, const int *edge,
1✔
369
                  int copy_fields)
370
{
371
    size_t i, N, I, nfields, field,
1✔
372
        idx[10] =
1✔
373
            {
374
                0,
375
            },
376
        cnt[10] =
1✔
377
            {
378
                0,
379
            },
380
        dimp[10] = {
1✔
381
            0,
382
        };
383
    matvar_t **fields, *struct_slab;
1✔
384
    int j;
1✔
385

386
    if ( matvar == NULL || start == NULL || stride == NULL || edge == NULL ) {
1✔
387
        return NULL;
388
    } else if ( matvar->rank > 9 ) {
1✔
389
        return NULL;
390
    } else if ( matvar->class_type != MAT_C_STRUCT && matvar->class_type != MAT_C_OBJECT ) {
1✔
391
        return NULL;
392
    }
393

394
    struct_slab = Mat_VarDuplicate(matvar, 0);
1✔
395
    if ( !copy_fields )
1✔
396
        struct_slab->mem_conserve = 1;
1✔
397

398
    nfields = matvar->internal->num_fields;
1✔
399

400
    dimp[0] = matvar->dims[0];
1✔
401
    N = edge[0];
1✔
402
    I = start[0];
1✔
403
    struct_slab->dims[0] = edge[0];
1✔
404
    idx[0] = start[0];
1✔
405
    for ( j = 1; j < matvar->rank; j++ ) {
4✔
406
        idx[j] = start[j];
3✔
407
        dimp[j] = dimp[j - 1] * matvar->dims[j];
3✔
408
        N *= edge[j];
3✔
409
        I += start[j] * dimp[j - 1];
3✔
410
        struct_slab->dims[j] = edge[j];
3✔
411
    }
412
    I *= nfields;
1✔
413
    struct_slab->nbytes = N * nfields * sizeof(matvar_t *);
1✔
414
    struct_slab->data = malloc(struct_slab->nbytes);
1✔
415
    if ( struct_slab->data == NULL ) {
1✔
UNCOV
416
        Mat_VarFree(struct_slab);
×
UNCOV
417
        return NULL;
×
418
    }
419
    fields = (matvar_t **)struct_slab->data;
420
    for ( i = 0; i < N; i += edge[0] ) {
13✔
421
        for ( j = 0; j < edge[0]; j++ ) {
24✔
422
            for ( field = 0; field < nfields; field++ ) {
36✔
423
                if ( copy_fields )
24✔
UNCOV
424
                    fields[(i + j) * nfields + field] =
×
UNCOV
425
                        Mat_VarDuplicate(*((matvar_t **)matvar->data + I), 1);
×
426
                else
427
                    fields[(i + j) * nfields + field] = *((matvar_t **)matvar->data + I);
24✔
428
                I++;
24✔
429
            }
430
            I += (stride[0] - 1) * nfields;
12✔
431
        }
432
        idx[0] = start[0];
12✔
433
        I = idx[0];
12✔
434
        cnt[1]++;
12✔
435
        idx[1] += stride[1];
12✔
436
        for ( j = 1; j < matvar->rank; j++ ) {
48✔
437
            if ( cnt[j] == (size_t)edge[j] ) {
36✔
438
                cnt[j] = 0;
9✔
439
                idx[j] = start[j];
9✔
440
                if ( j < matvar->rank - 1 ) {
9✔
441
                    cnt[j + 1]++;
8✔
442
                    idx[j + 1] += stride[j + 1];
8✔
443
                }
444
            }
445
            I += idx[j] * dimp[j - 1];
36✔
446
        }
447
        I *= nfields;
12✔
448
    }
449
    return struct_slab;
450
}
451

452
/** @brief Indexes a structure
453
 *
454
 * Finds structures of a structure array given a single (linear)start, stride,
455
 * and edge.  The structures are placed in a new structure array.  If
456
 * copy_fields is non-zero, the indexed structures are copied and should be
457
 * freed, but if copy_fields is zero, the indexed structures are pointers to
458
 * the original, but should still be freed since the mem_conserve flag is set
459
 * so that the structures are not freed.
460
 * MAT file version must be 5.
461
 * @ingroup MAT
462
 * @param matvar Structure matlab variable
463
 * @param start starting index (0-relative)
464
 * @param stride stride (1 reads consecutive elements)
465
 * @param edge Number of elements to read
466
 * @param copy_fields 1 to copy the fields, 0 to just set pointers to them.
467
 * @returns A new structure with fields indexed from matvar
468
 */
469
matvar_t *
470
Mat_VarGetStructsLinear(const matvar_t *matvar, int start, int stride, int edge, int copy_fields)
3✔
471
{
472
    matvar_t *struct_slab;
3✔
473

474
    if ( matvar == NULL || matvar->rank > 10 ) {
3✔
475
        struct_slab = NULL;
476
    } else {
477
        int i, I, field, nfields;
3✔
478
        matvar_t **fields;
3✔
479

480
        struct_slab = Mat_VarDuplicate(matvar, 0);
3✔
481
        if ( !copy_fields )
3✔
482
            struct_slab->mem_conserve = 1;
3✔
483

484
        nfields = matvar->internal->num_fields;
3✔
485

486
        struct_slab->nbytes = (size_t)edge * nfields * sizeof(matvar_t *);
3✔
487
        struct_slab->data = malloc(struct_slab->nbytes);
3✔
488
        if ( struct_slab->data == NULL ) {
3✔
UNCOV
489
            Mat_VarFree(struct_slab);
×
UNCOV
490
            return NULL;
×
491
        }
492
        struct_slab->dims[0] = edge;
3✔
493
        struct_slab->dims[1] = 1;
3✔
494
        fields = (matvar_t **)struct_slab->data;
3✔
495
        I = start * nfields;
3✔
496
        for ( i = 0; i < edge; i++ ) {
13✔
497
            if ( copy_fields ) {
10✔
UNCOV
498
                for ( field = 0; field < nfields; field++ ) {
×
UNCOV
499
                    fields[i * nfields + field] =
×
UNCOV
500
                        Mat_VarDuplicate(*((matvar_t **)matvar->data + I), 1);
×
UNCOV
501
                    I++;
×
502
                }
503
            } else {
504
                for ( field = 0; field < nfields; field++ ) {
40✔
505
                    fields[i * nfields + field] = *((matvar_t **)matvar->data + I);
30✔
506
                    I++;
30✔
507
                }
508
            }
509
            I += (stride - 1) * nfields;
10✔
510
        }
511
    }
512
    return struct_slab;
513
}
514

515
/** @brief Sets the structure field to the given variable
516
 *
517
 * Sets the structure field specified by the 0-relative field index
518
 * @c field_index for the given 0-relative structure index @c index to
519
 * @c field.
520
 * @ingroup MAT
521
 * @param matvar Pointer to the structure MAT variable
522
 * @param field_index 0-relative index of the field.
523
 * @param index linear index of the structure array
524
 * @param field New field variable
525
 * @return Pointer to the previous field (NULL if no previous field)
526
 */
527
matvar_t *
528
Mat_VarSetStructFieldByIndex(matvar_t *matvar, size_t field_index, size_t index, matvar_t *field)
4✔
529
{
530
    int err;
4✔
531
    matvar_t *old_field = NULL;
4✔
532
    size_t nelems = 1, nfields;
4✔
533

534
    if ( matvar == NULL || matvar->class_type != MAT_C_STRUCT || matvar->data == NULL )
4✔
535
        return NULL;
536

537
    err = Mat_MulDims(matvar, &nelems);
4✔
538
    if ( err )
4✔
539
        return NULL;
540

541
    nfields = matvar->internal->num_fields;
4✔
542

543
    if ( index < nelems && field_index < nfields ) {
4✔
544
        matvar_t **fields = (matvar_t **)matvar->data;
4✔
545
        old_field = fields[index * nfields + field_index];
4✔
546
        fields[index * nfields + field_index] = field;
4✔
547
        if ( NULL != field->name ) {
4✔
548
            free(field->name);
4✔
549
        }
550
        field->name = strdup(matvar->internal->fieldnames[field_index]);
4✔
551
    }
552

553
    return old_field;
554
}
555

556
/** @brief Sets the structure field to the given variable
557
 *
558
 * Sets the specified structure fieldname at the given 0-relative @c index to
559
 * @c field.
560
 * @ingroup MAT
561
 * @param matvar Pointer to the Structure MAT variable
562
 * @param field_name Name of the structure field
563
 * @param index linear index of the structure array
564
 * @param field New field variable
565
 * @return Pointer to the previous field (NULL if no previous field)
566
 */
567
matvar_t *
568
Mat_VarSetStructFieldByName(matvar_t *matvar, const char *field_name, size_t index, matvar_t *field)
780✔
569
{
570
    int err, i, nfields, field_index;
780✔
571
    matvar_t *old_field = NULL;
780✔
572
    size_t nelems = 1;
780✔
573

574
    if ( matvar == NULL || matvar->class_type != MAT_C_STRUCT || matvar->data == NULL )
780✔
575
        return NULL;
576

577
    err = Mat_MulDims(matvar, &nelems);
780✔
578
    if ( err )
780✔
579
        return NULL;
580

581
    nfields = matvar->internal->num_fields;
780✔
582
    field_index = -1;
780✔
583
    for ( i = 0; i < nfields; i++ ) {
1,184✔
584
        if ( !strcmp(matvar->internal->fieldnames[i], field_name) ) {
1,184✔
585
            field_index = i;
586
            break;
587
        }
588
    }
589

590
    if ( index < nelems && field_index >= 0 ) {
780✔
591
        matvar_t **fields = (matvar_t **)matvar->data;
780✔
592
        old_field = fields[index * nfields + field_index];
780✔
593
        fields[index * nfields + field_index] = field;
780✔
594
        if ( NULL != field->name ) {
780✔
595
            free(field->name);
16✔
596
        }
597
        field->name = strdup(matvar->internal->fieldnames[field_index]);
780✔
598
    }
599

600
    return old_field;
601
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc