Coverage Report

Created: 2026-01-17 06:38

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/testdir/build/lua-master/source/lzio.c
Line
Count
Source
1
/*
2
** $Id: lzio.c $
3
** Buffered streams
4
** See Copyright Notice in lua.h
5
*/
6
7
#define lzio_c
8
#define LUA_CORE
9
10
#include "lprefix.h"
11
12
13
#include <string.h>
14
15
#include "lua.h"
16
17
#include "lapi.h"
18
#include "llimits.h"
19
#include "lmem.h"
20
#include "lstate.h"
21
#include "lzio.h"
22
23
24
5.72M
int luaZ_fill (ZIO *z) {
25
5.72M
  size_t size;
26
5.72M
  lua_State *L = z->L;
27
5.72M
  const char *buff;
28
5.72M
  lua_unlock(L);
29
5.72M
  buff = z->reader(L, z->data, &size);
30
5.72M
  lua_lock(L);
31
5.72M
  if (buff == NULL || size == 0)
32
1.90M
    return EOZ;
33
3.81M
  z->n = size - 1;  /* discount char being returned */
34
3.81M
  z->p = buff;
35
3.81M
  return cast_uchar(*(z->p++));
36
5.72M
}
37
38
39
4.10M
void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) {
40
4.10M
  z->L = L;
41
4.10M
  z->reader = reader;
42
4.10M
  z->data = data;
43
4.10M
  z->n = 0;
44
4.10M
  z->p = NULL;
45
4.10M
}
46
47
48
/* --------------------------------------------------------------- read --- */
49
50
122k
static int checkbuffer (ZIO *z) {
51
122k
  if (z->n == 0) {  /* no bytes in buffer? */
52
60
    if (luaZ_fill(z) == EOZ)  /* try to read more */
53
60
      return 0;  /* no more input */
54
0
    else {
55
0
      z->n++;  /* luaZ_fill consumed first byte; put it back */
56
0
      z->p--;
57
0
    }
58
60
  }
59
122k
  return 1;  /* now buffer has something */
60
122k
}
61
62
63
124k
size_t luaZ_read (ZIO *z, void *b, size_t n) {
64
247k
  while (n) {
65
122k
    size_t m;
66
122k
    if (!checkbuffer(z))
67
60
      return n;  /* no more input; return number of missing bytes */
68
122k
    m = (n <= z->n) ? n : z->n;  /* min. between n and z->n */
69
122k
    memcpy(b, z->p, m);
70
122k
    z->n -= m;
71
122k
    z->p += m;
72
122k
    b = (char *)b + m;
73
122k
    n -= m;
74
122k
  }
75
124k
  return 0;
76
124k
}
77
78
79
0
const void *luaZ_getaddr (ZIO* z, size_t n) {
80
0
  const void *res;
81
0
  if (!checkbuffer(z))
82
0
    return NULL;  /* no more input */
83
0
  if (z->n < n)  /* not enough bytes? */
84
0
    return NULL;  /* block not whole; cannot give an address */
85
0
  res = z->p;  /* get block address */
86
0
  z->n -= n;  /* consume these bytes */
87
0
  z->p += n;
88
0
  return res;
89
0
}