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

polserver / polserver / 16683711876

01 Aug 2025 07:40PM UTC coverage: 59.756% (-0.03%) from 59.79%
16683711876

push

github

web-flow
use c++20 (#799)

* use c++20
* increased used clang version
* compiler report and logfacility use now compile time formatting, which
means that the formatstring gets checked at compile time. (which found 2 errors)
adapted a few places since report only accepts formatting arguments
adapted a few places with logging since char[] is compile time
formatting and string or chr* is runtime formatting
* use std::ranges instead of boost
* disabled pragma_assume vs specific macro (I guess noone cares)
* needed to fix ancient ms exception code
* modernized SpinLock
* removed unused code in ECompile
* replaced std::filesystem::path::u8string with string. It now returns an actual u8string type
* cleanup layers.h added the defines for other layers which where before
  only defined in the pkt
* osmod::OpenConnection and HTTPRequest cleanup: early outs, dont check for pChild which is
  only needed for startscript and placed suspend at the very last
  position

* fix warning

* rebuild cache with new compiler version

* define c++ standard for external libs where possible

* added fixme

156 of 212 new or added lines in 26 files covered. (73.58%)

45 existing lines in 19 files now uncovered.

43621 of 72999 relevant lines covered (59.76%)

409874.73 hits per line

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

57.63
/pol-core/pol/module/utilmod.cpp
1
/** @file
2
 *
3
 * @par History
4
 * - 2006/10/07 Shinigami: GCC 3.4.x fix - added "template<>" to TmplExecutorModule
5
 * - 2008/07/08 Turley:    Added mf_RandomIntMinMax - Return Random Value between...
6
 * - 2011/01/07 Nando:     fix uninit in mf_StrFormatTime - strftime's return is now tested
7
 */
8

9

10
#include "utilmod.h"
11
#include <algorithm>
12
#include <ctime>
13
#include <string>
14
#include <vector>
15

16
#include "../../bscript/berror.h"
17
#include "../../bscript/impstr.h"
18
#include "../../clib/clib.h"
19
#include "../../clib/random.h"
20
#include "../dice.h"
21

22
#include <module_defs/util.h>
23

24
namespace Pol
25
{
26
namespace Module
27
{
28
using namespace Bscript;
29

30
UtilExecutorModule::UtilExecutorModule( Bscript::Executor& exec )
2,220✔
31
    : Bscript::TmplExecutorModule<UtilExecutorModule, Bscript::ExecutorModule>( exec )
2,220✔
32
{
33
}
2,220✔
34

35
Bscript::BObjectImp* UtilExecutorModule::mf_RandomInt()
×
36
{
37
  int value;
38
  if ( exec.getParam( 0, value, 1, INT_MAX ) )
×
39
  {
40
    if ( value > 0 )
×
41
      return new BLong( Clib::random_int( value - 1 ) );
×
42
    else
43
      return new BError( "RandomInt() expects a positive integer" );
×
44
  }
45
  else
46
  {
47
    return new BError( "RandomInt() expects a positive integer" );
×
48
  }
49
}
50

51
Bscript::BObjectImp* UtilExecutorModule::mf_RandomIntMinMax()
×
52
{
53
  int minvalue;
54
  if ( exec.getParam( 0, minvalue, INT_MIN, INT_MAX ) )
×
55
  {
56
    int maxvalue;
57
    if ( exec.getParam( 1, maxvalue, INT_MIN, INT_MAX ) )
×
58
    {
59
      maxvalue--;
×
60
      return new BLong( Clib::random_int_range( minvalue, maxvalue ) );
×
61
    }
62
    else
63
      return new BError( "RandomIntMinMax() expects an integer" );
×
64
  }
65
  else
66
    return new BError( "RandomIntMinMax() expects an integer" );
×
67
}
68

69
Bscript::BObjectImp* UtilExecutorModule::mf_RandomFloat()
×
70
{
71
  double value;
72
  if ( exec.getRealParam( 0, value ) )
×
73
  {
74
    return new Double( Clib::random_double( value ) );
×
75
  }
76
  else
77
  {
78
    return new BError( "RandomFloat() expects a Real parameter" );
×
79
  }
80
}
81

82
Bscript::BObjectImp* UtilExecutorModule::mf_RandomDiceRoll()
12✔
83
{
84
  const String* dicestr;
85
  bool allow_negatives;
86

87
  if ( exec.getStringParam( 0, dicestr ) && exec.getParam( 1, allow_negatives ) )
12✔
88
  {
89
    std::string errormsg;
12✔
90
    Core::Dice dice;
12✔
91
    if ( dice.load( dicestr->data(), &errormsg ) )
12✔
92
    {
93
      if ( allow_negatives )
12✔
94
        return new BLong( dice.roll_with_negatives() );
3✔
95
      else
96
        return new BLong( dice.roll() );
9✔
97
    }
98
    else
99
    {
100
      return new BError( errormsg.c_str() );
×
101
    }
102
  }
12✔
103
  else
104
  {
105
    return new BError( "RandomDiceRoll() expects a String as parameter" );
×
106
  }
107
}
108

109
Bscript::BObjectImp* UtilExecutorModule::mf_StrFormatTime()
15✔
110
{
111
  const String* format_string;
112
  if ( !getStringParam( 0, format_string ) )
15✔
113
    return new BError( "No time string passed." );
×
114

115
  int time_stamp;
116
  if ( !getParam( 1, time_stamp, 0, INT_MAX ) )
15✔
117
    time_stamp = 0;
×
118

119
  time_t seconds;
120

121

122
  if ( time_stamp <= 0 )
15✔
123
    seconds = time( nullptr );
6✔
124
  else
125
    seconds = time_stamp;
9✔
126

127
  auto time_struct = Clib::localtime( seconds );
15✔
128

129
  // strftime uses assert check for invalid format -> precheck it
130
  size_t len = format_string->length();
15✔
131
  const char* str = format_string->data();
15✔
132
  while ( len-- > 0 )
138✔
133
  {
134
    if ( *str++ == '%' )
114✔
135
    {
136
      if ( len-- <= 0 )
30✔
137
        return new BError( "Invalid Format string." );
3✔
138
      switch ( *str++ )
27✔
139
      {
140
        // vs2019 does not support 0 and E formats
141
        /*
142
      case ( '0' ):
143
      {
144
        if ( len-- <= 0 )
145
          return new BError( "Invalid Format string." );
146
        switch ( *str++ )
147
        {
148
        case ( 'd' ):
149
        case ( 'e' ):
150
        case ( 'H' ):
151
        case ( 'I' ):
152
        case ( 'm' ):
153
        case ( 'M' ):
154
        case ( 'S' ):
155
        case ( 'u' ):
156
        case ( 'U' ):
157
        case ( 'V' ):
158
        case ( 'w' ):
159
        case ( 'W' ):
160
        case ( 'y' ):
161
          continue;
162
        default:
163
          return new BError( "Invalid Format string." );
164
        }
165
        continue;
166
      }
167
      case ( 'E' ):
168
      {
169
        if ( len-- <= 0 )
170
          return new BError( "Invalid Format string." );
171
        switch ( *str++ )
172
        {
173
        case ( 'c' ):
174
        case ( 'C' ):
175
        case ( 'x' ):
176
        case ( 'X' ):
177
        case ( 'y' ):
178
        case ( 'Y' ):
179
          continue;
180
        default:
181
          return new BError( "Invalid Format string." );
182
        }
183
        continue;
184
      }
185
      */
186
      case ( '%' ):
24✔
187
      case ( 'a' ):
188
      case ( 'A' ):
189
      case ( 'b' ):
190
      case ( 'B' ):
191
      case ( 'c' ):
192
      case ( 'C' ):
193
      case ( 'd' ):
194
      case ( 'D' ):
195
      case ( 'e' ):
196
      case ( 'F' ):
197
      case ( 'g' ):
198
      case ( 'G' ):
199
      case ( 'h' ):
200
      case ( 'H' ):
201
      case ( 'I' ):
202
      case ( 'j' ):
203
      case ( 'n' ):
204
      case ( 'm' ):
205
      case ( 'M' ):
206
      case ( 'p' ):
207
      case ( 'r' ):
208
      case ( 'R' ):
209
      case ( 'S' ):
210
      case ( 't' ):
211
      case ( 'T' ):
212
      case ( 'u' ):
213
      case ( 'U' ):
214
      case ( 'V' ):
215
      case ( 'w' ):
216
      case ( 'W' ):
217
      case ( 'x' ):
218
      case ( 'X' ):
219
      case ( 'y' ):
220
      case ( 'Y' ):
221
      case ( 'z' ):
222
      case ( 'Z' ):
223
        continue;
24✔
224
      case ( '\0' ):
×
225
        len = 0;
×
226
        break;
×
227
      default:
3✔
228
        return new BError( "Invalid Format string." );
3✔
229
      }
230
    }
231
  }
232

UNCOV
233
  std::vector<char> buffer;
×
234
  buffer.resize( std::max( format_string->length() * 2, (size_t)50u ) );
9✔
235
  while ( strftime( buffer.data(), buffer.capacity(), format_string->data(), &time_struct ) == 0 )
12✔
236
  {
237
    buffer.resize( buffer.capacity() * 2 );
3✔
238
  }
239
  return new String( buffer.data() );
9✔
240
}
241
}  // namespace Module
242
}  // 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