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

polserver / polserver / 21066490217

16 Jan 2026 12:22PM UTC coverage: 60.507%. Remained the same
21066490217

push

github

web-flow
misc clang-tidy (#853)

* trigger tidy

* Automated clang-tidy change: modernize-use-equals-delete,modernize-make-shared,modernize-make-unique,modernize-use-constraints,readability-container-size-empty,modernize-redundant-void-arg,modernize-use-emplace

* removed non needed macros

* missed to disable tidy build

---------

Co-authored-by: Clang Tidy <clang-tidy@users.noreply.github.com>

174 of 248 new or added lines in 74 files covered. (70.16%)

2 existing lines in 2 files now uncovered.

44459 of 73477 relevant lines covered (60.51%)

515895.79 hits per line

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

21.9
/pol-core/bscript/symcont.cpp
1
/** @file
2
 *
3
 * @par History
4
 * - 2006/10/06 Shinigami: malloc.h -> stdlib.h
5
 */
6

7

8
#include "symcont.h"
9

10
#include <cstdio>
11
#include <cstdlib>
12
#include <cstring>
13
#include <string>
14

15
#include "../clib/logfacility.h"
16
#include "../clib/strutil.h"
17

18
namespace Pol
19
{
20
namespace Bscript
21
{
22
SymbolContainer::SymbolContainer( int PgrowBy )
4,286✔
23
{
24
  s = nullptr;
4,286✔
25
  usedLen = allocLen = 0u;
4,286✔
26
  growBy = PgrowBy;
4,286✔
27
}
4,286✔
28
SymbolContainer::~SymbolContainer()
3,974✔
29
{
30
  if ( s )
3,974✔
31
    free( s );
3,972✔
32
  s = nullptr;
3,974✔
33
}
3,974✔
34

35
void SymbolContainer::erase()
×
36
{
37
  if ( s )
×
38
    free( s );
×
39
  s = nullptr;
×
40
  usedLen = allocLen = 0;
×
41
}
×
42

43
void SymbolContainer::resize( unsigned lengthToAdd )
×
44
{
45
  while ( usedLen + lengthToAdd > allocLen )
×
46
  {
47
    allocLen += growBy;
×
48
    if ( s == nullptr )
×
49
    {
50
      s = (char*)calloc( 1, (unsigned)allocLen );
×
51
      usedLen = 0;
×
52
    }
53
    else
54
    {
55
      char* t = (char*)realloc( s, allocLen );
×
56
      if ( t )
×
57
        s = t;
×
58
      else
59
        throw std::runtime_error( "allocation failure in SymbolContainer::resize(" +
×
60
                                  Clib::tostring( allocLen ) + ")" );
×
61
    }
62
  }
63
}
×
64

65
bool SymbolContainer::findexisting( const void* data, int datalen, unsigned& position )
×
66
{
67
  int nstarting = usedLen - datalen + 1;
×
68
  // don't use the first byte, because that's the "fake null"
69
  for ( int i = 1; i < nstarting; i++ )
×
70
  {
71
    if ( memcmp( s + i, data, datalen ) == 0 )
×
72
    {
73
      position = i;
×
74
      return true;
×
75
    }
76
  }
77
  return false;
×
78
}
79

80
void SymbolContainer::append( const char* string, unsigned& position )
×
81
{
82
  int nChars = static_cast<unsigned int>( strlen( string ) + 1 );
×
83
  if ( findexisting( string, nChars, position ) )
×
84
    return;
×
85
  resize( nChars );
×
86
  strcpy( s + usedLen, string );
×
87
  position = usedLen;
×
88
  usedLen += nChars;
×
89
}
90

91
void SymbolContainer::append( int lvalue, unsigned& position )
×
92
{
93
  resize( sizeof lvalue );
×
94
  std::memcpy( s + usedLen, &lvalue, sizeof( int ) );
×
95
  position = usedLen;
×
96
  usedLen += sizeof lvalue;
×
97
}
×
98

99
void SymbolContainer::append( double dvalue, unsigned& position )
×
100
{
101
  resize( sizeof dvalue );
×
102
  std::memcpy( s + usedLen, &dvalue, sizeof( double ) );
×
103
  position = usedLen;
×
104
  usedLen += sizeof dvalue;
×
105
}
×
106

107
void SymbolContainer::append( void* data, unsigned datalen, unsigned& position )
×
108
{
109
  resize( datalen );
×
110
  if ( findexisting( data, datalen, position ) )
×
111
    return;
×
112
  memcpy( s + usedLen, data, datalen );
×
113
  position = usedLen;
×
114
  usedLen += datalen;
×
115
}
116

117
void SymbolContainer::write( FILE* fp )
×
118
{
119
  if ( fwrite( &usedLen, sizeof usedLen, 1, fp ) != 1 )
×
120
    throw std::runtime_error( "SymbolContainer::write failed" );
×
121
  if ( fwrite( s, usedLen, 1, fp ) != 1 )
×
122
    throw std::runtime_error( "SymbolContainer::write failed" );
×
123
}
×
124

125
unsigned int SymbolContainer::get_write_length() const
×
126
{
127
  // we write the length, followed by the actual data.
128
  return sizeof usedLen + usedLen;
×
129
}
130

131
void SymbolContainer::write( char* fname )
×
132
{
133
  FILE* fp = fopen( fname, "wb" );
×
134
  if ( !fp )
×
135
    throw std::runtime_error( std::string( "Unable to open " ) + fname + " for writing." );
×
136
  write( fp );
×
137
  fclose( fp );
×
138
}
×
139

140
void SymbolContainer::read( FILE* fp )
4,284✔
141
{
142
  size_t fread_res = fread( &usedLen, sizeof usedLen, 1, fp );
4,284✔
143
  if ( fread_res != 1 )
4,284✔
144
    throw std::runtime_error( "failed to read in SymbolContainer::read()." );
×
145
  char* new_s = (char*)realloc( s, usedLen );
4,284✔
146
  if ( !new_s )
4,284✔
147
    throw std::runtime_error( "allocation failure in SymbolContainer::read()." );
×
148
  s = new_s;
4,284✔
149
  fread_res = fread( s, usedLen, 1, fp );
4,284✔
150
  if ( fread_res != 1 )
4,284✔
151
    throw std::runtime_error( "failed to read in SymbolContainer::read()." );
×
152
  allocLen = usedLen;
4,284✔
153
}
4,284✔
154

155
void StoredTokenContainer::read( FILE* fp )
2,142✔
156
{
157
  SymbolContainer::read( fp );
2,142✔
158
  ST = (StoredToken*)s;
2,142✔
159
}
2,142✔
160

161
void SymbolContainer::read( char* fname )
×
162
{
163
  FILE* fp = fopen( fname, "rb" );
×
164
  if ( !fp )
×
165
    throw std::runtime_error( std::string( "Unable to open " ) + fname + " for reading." );
×
166
  read( fp );
×
167
  fclose( fp );
×
168
}
×
169

170
void StoredTokenContainer::append_tok( const StoredToken& sToken, unsigned* pposition )
×
171
{
172
  resize( sizeof sToken );
×
173
  unsigned position = usedLen / sizeof( StoredToken );
×
174
  usedLen += sizeof sToken;
×
175
  atPut1( sToken, position );
×
176
  if ( pposition )
×
177
    *pposition = position;
×
178
}
×
179

180
void StoredTokenContainer::atPut1( const StoredToken& sToken, unsigned position )
×
181
{
182
  if ( position >= count() )
×
183
    throw std::runtime_error( "Assigning token at invalid position " + Clib::tostring( position ) +
×
184
                              ", range is 0.." + Clib::tostring( count() - 1 ) );
×
185

186
  char* dst = s + position * sizeof( StoredToken );
×
187
  StoredToken* st = (StoredToken*)dst;
×
188
  *st = sToken;
×
189
}
×
190

191
void StoredTokenContainer::atGet1( unsigned position, StoredToken& sToken ) const
160,356✔
192
{
193
  if ( position >= count() )
160,356✔
194
    throw std::runtime_error( "Retrieving token at invalid position " + Clib::tostring( position ) +
×
195
                              ", range is 0.." + Clib::tostring( count() - 1 ) );
×
196

197
  char* src = s + position * sizeof( StoredToken );
160,356✔
198
  StoredToken* st = (StoredToken*)src;
160,356✔
199

200
  sToken = *st;
160,356✔
201
}
160,356✔
202

NEW
203
void StoredTokenContainer::pack()
×
204
{
205
  SymbolContainer::pack();
×
206
  ST = (StoredToken*)s;
×
207
}
×
208

NEW
209
void* StoredTokenContainer::detach()
×
210
{
211
  void* d = SymbolContainer::detach();
×
212
  ST = nullptr;
×
213
  return d;
×
214
}
215

216
void StoredTokenContainer::resize( unsigned lengthToAdd )
×
217
{
218
  SymbolContainer::resize( lengthToAdd );
×
219
  ST = (StoredToken*)s;
×
220
}
×
221

222
}  // namespace Bscript
223
}  // namespace Pol
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