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

polserver / polserver / 21108840797

18 Jan 2026 08:35AM UTC coverage: 60.508% (+0.02%) from 60.492%
21108840797

push

github

web-flow
ClangTidy readability-else-after-return (#857)

* trigger tidy

* Automated clang-tidy change: readability-else-after-return

* compile test

* rerun

* Automated clang-tidy change: readability-else-after-return

* trigger..

* Automated clang-tidy change: readability-else-after-return

* manually removed a few

* Automated clang-tidy change: readability-else-after-return

* removed duplicate code

* fix remaining warnings

* fixed scope

---------

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

837 of 1874 new or added lines in 151 files covered. (44.66%)

46 existing lines in 25 files now uncovered.

44448 of 73458 relevant lines covered (60.51%)

525066.38 hits per line

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

64.79
/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 <boost/uuid/time_generator_v7.hpp>
13
#include <boost/uuid/uuid.hpp>
14
#include <boost/uuid/uuid_generators.hpp>
15
#include <boost/uuid/uuid_io.hpp>
16
#include <ctime>
17
#include <string>
18
#include <vector>
19

20
#include "../../bscript/berror.h"
21
#include "../../bscript/impstr.h"
22
#include "../../clib/clib.h"
23
#include "../../clib/random.h"
24
#include "../dice.h"
25

26
#include <module_defs/util.h>
27

28

29
namespace Pol::Module
30
{
31
using namespace Bscript;
32

33
UtilExecutorModule::UtilExecutorModule( Bscript::Executor& exec )
2,356✔
34
    : Bscript::TmplExecutorModule<UtilExecutorModule, Bscript::ExecutorModule>( exec )
2,356✔
35
{
36
}
2,356✔
37

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

NEW
48
  return new BError( "RandomInt() expects a positive integer" );
×
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
    }
UNCOV
62
    return new BError( "RandomIntMinMax() expects an integer" );
×
63
  }
NEW
64
  return new BError( "RandomIntMinMax() expects an integer" );
×
65
}
66

67
Bscript::BObjectImp* UtilExecutorModule::mf_RandomFloat()
×
68
{
69
  double value;
70
  if ( exec.getRealParam( 0, value ) )
×
71
  {
72
    return new Double( Clib::random_double( value ) );
×
73
  }
74

NEW
75
  return new BError( "RandomFloat() expects a Real parameter" );
×
76
}
77

78
Bscript::BObjectImp* UtilExecutorModule::mf_RandomDiceRoll()
12✔
79
{
80
  const String* dicestr;
81
  bool allow_negatives;
82

83
  if ( exec.getStringParam( 0, dicestr ) && exec.getParam( 1, allow_negatives ) )
12✔
84
  {
85
    std::string errormsg;
12✔
86
    Core::Dice dice;
12✔
87
    if ( dice.load( dicestr->data(), &errormsg ) )
12✔
88
    {
89
      if ( allow_negatives )
12✔
90
        return new BLong( dice.roll_with_negatives() );
3✔
91
      return new BLong( dice.roll() );
9✔
92
    }
93

NEW
94
    return new BError( errormsg.c_str() );
×
95
  }
12✔
96

NEW
97
  return new BError( "RandomDiceRoll() expects a String as parameter" );
×
98
}
99

100
Bscript::BObjectImp* UtilExecutorModule::mf_StrFormatTime()
15✔
101
{
102
  const String* format_string;
103
  if ( !getStringParam( 0, format_string ) )
15✔
104
    return new BError( "No time string passed." );
×
105

106
  int time_stamp;
107
  if ( !getParam( 1, time_stamp, 0, INT_MAX ) )
15✔
108
    time_stamp = 0;
×
109

110
  time_t seconds;
111

112

113
  if ( time_stamp <= 0 )
15✔
114
    seconds = time( nullptr );
6✔
115
  else
116
    seconds = time_stamp;
9✔
117

118
  auto time_struct = Clib::localtime( seconds );
15✔
119

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

224
  std::vector<char> buffer;
×
225
  buffer.resize( std::max( format_string->length() * 2, (size_t)50u ) );
9✔
226
  while ( strftime( buffer.data(), buffer.capacity(), format_string->data(), &time_struct ) == 0 )
12✔
227
  {
228
    buffer.resize( buffer.capacity() * 2 );
3✔
229
  }
230
  return new String( buffer.data() );
9✔
231
}
232

233
Bscript::BObjectImp* UtilExecutorModule::mf_RandomUUID()
12✔
234
{
235
  int value;
236
  if ( !exec.getParam( 0, value ) )
12✔
237
    return new BError( "Invalid parameter type" );
3✔
238
  if ( value != 4 && value != 7 )
9✔
239
    return new BError( "Invalid version" );
3✔
240

241
  if ( value == 7 )
6✔
242
  {
243
    static auto uuid_generator = boost::uuids::time_generator_v7();
3✔
244

245
    boost::uuids::uuid uuid = (uuid_generator)();
3✔
246
    return new String( boost::uuids::to_string( uuid ) );
3✔
247
  }
248

249
  static auto uuid_generator = boost::uuids::random_generator();
3✔
250

251
  boost::uuids::uuid uuid = (uuid_generator)();
3✔
252
  return new String( boost::uuids::to_string( uuid ) );
3✔
253
}
254
}  // namespace Pol::Module
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