Coverage Report

Created: 2025-07-12 06:33

/src/libcbor/src/cbor/internal/stack.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright (c) 2014-2020 Pavel Kalvoda <me@pavelkalvoda.com>
3
 *
4
 * libcbor is free software; you can redistribute it and/or modify
5
 * it under the terms of the MIT license. See LICENSE for details.
6
 */
7
8
#include "stack.h"
9
10
39.4k
struct _cbor_stack _cbor_stack_init(void) {
11
39.4k
  return (struct _cbor_stack){.top = NULL, .size = 0};
12
39.4k
}
13
14
206k
void _cbor_stack_pop(struct _cbor_stack *stack) {
15
206k
  struct _cbor_stack_record *top = stack->top;
16
206k
  stack->top = stack->top->lower;
17
206k
  _cbor_free(top);
18
206k
  stack->size--;
19
206k
}
20
21
struct _cbor_stack_record *_cbor_stack_push(struct _cbor_stack *stack,
22
                                            cbor_item_t *item,
23
206k
                                            size_t subitems) {
24
206k
  if (stack->size == CBOR_MAX_STACK_SIZE) return NULL;
25
206k
  struct _cbor_stack_record *new_top =
26
206k
      _cbor_malloc(sizeof(struct _cbor_stack_record));
27
206k
  if (new_top == NULL) return NULL;
28
29
206k
  *new_top = (struct _cbor_stack_record){stack->top, item, subitems};
30
206k
  stack->top = new_top;
31
206k
  stack->size++;
32
206k
  return new_top;
33
206k
}