cosmos 4.5.0-java → 4.5.1-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/Dockerfile +2 -1
  3. data/Rakefile +10 -8
  4. data/autohotkey/tools/cmd_extractor.ahk +11 -9
  5. data/autohotkey/tools/cmd_sender.ahk +1 -1
  6. data/autohotkey/tools/cmd_sequence.ahk +1 -1
  7. data/autohotkey/tools/data_viewer.ahk +1 -1
  8. data/autohotkey/tools/limits_monitor.ahk +1 -1
  9. data/autohotkey/tools/packet_viewer.ahk +1 -1
  10. data/autohotkey/tools/script_runner.ahk +1 -1
  11. data/autohotkey/tools/test_runner2.ahk +1 -1
  12. data/autohotkey/tools/tlm_grapher.ahk +1 -1
  13. data/autohotkey/tools/tlm_grapher3.ahk +1 -1
  14. data/autohotkey/tools/tlm_viewer.ahk +1 -1
  15. data/autohotkey/tools/tlm_viewer2.ahk +1 -1
  16. data/autohotkey/tools/tlm_viewer5.ahk +1 -1
  17. data/bin/xtce_converter +1 -1
  18. data/data/crc.txt +403 -403
  19. data/demo/Rakefile +4 -4
  20. data/demo/config/data/crc.txt +210 -210
  21. data/ext/cosmos/ext/buffered_file/buffered_file.c +2 -2
  22. data/ext/cosmos/ext/config_parser/config_parser.c +1 -2
  23. data/ext/cosmos/ext/line_graph/line_graph.c +53 -94
  24. data/ext/cosmos/ext/platform/platform.c +56 -21
  25. data/ext/cosmos/ext/polynomial_conversion/polynomial_conversion.c +4 -8
  26. data/ext/cosmos/ext/structure/structure.c +12 -0
  27. data/install/Rakefile +4 -4
  28. data/install/config/data/crc.txt +129 -129
  29. data/lib/cosmos/config/config_parser.rb +2 -10
  30. data/lib/cosmos/core_ext/class.rb +10 -0
  31. data/lib/cosmos/core_ext/time.rb +2 -2
  32. data/lib/cosmos/dart/lib/dart_common.rb +3 -3
  33. data/lib/cosmos/dart/spec/dart/dart_database_cleaner_spec.rb +2 -2
  34. data/lib/cosmos/gui/qt.rb +10 -10
  35. data/lib/cosmos/gui/qt_tool.rb +7 -0
  36. data/lib/cosmos/gui/text/completion_text_edit.rb +2 -0
  37. data/lib/cosmos/interfaces/tcpip_server_interface.rb +3 -3
  38. data/lib/cosmos/io/io_multiplexer.rb +6 -2
  39. data/lib/cosmos/io/json_drb.rb +1 -1
  40. data/lib/cosmos/packets/packet.rb +8 -8
  41. data/lib/cosmos/packets/packet_config.rb +1 -1
  42. data/lib/cosmos/packets/parsers/xtce_converter.rb +10 -10
  43. data/lib/cosmos/packets/parsers/xtce_parser.rb +3 -0
  44. data/lib/cosmos/packets/structure.rb +16 -12
  45. data/lib/cosmos/script/api_shared.rb +10 -0
  46. data/lib/cosmos/script/script.rb +2 -2
  47. data/lib/cosmos/tools/cmd_tlm_server/api.rb +10 -8
  48. data/lib/cosmos/tools/cmd_tlm_server/gui/logging_tab.rb +1 -1
  49. data/lib/cosmos/tools/cmd_tlm_server/interface_thread.rb +29 -26
  50. data/lib/cosmos/tools/cmd_tlm_server/limits_groups_background_task.rb +1 -1
  51. data/lib/cosmos/tools/script_runner/script_runner_frame.rb +5 -2
  52. data/lib/cosmos/tools/test_runner/test.rb +1 -1
  53. data/lib/cosmos/tools/test_runner/test_runner.rb +4 -4
  54. data/lib/cosmos/tools/tlm_extractor/tlm_extractor.rb +3 -3
  55. data/lib/cosmos/tools/tlm_viewer/widgets/canvasdot_widget.rb +2 -0
  56. data/lib/cosmos/top_level.rb +1 -1
  57. data/lib/cosmos/utilities/simulated_target.rb +1 -1
  58. data/lib/cosmos/version.rb +4 -4
  59. data/spec/core_ext/class_spec.rb +54 -0
  60. data/spec/interfaces/serial_interface_spec.rb +1 -5
  61. data/spec/packet_logs/packet_log_reader_spec.rb +1 -1
  62. data/spec/system/system_spec.rb +1 -1
  63. data/spec/tools/cmd_tlm_server/api_spec.rb +12 -12
  64. data/spec/tools/cmd_tlm_server/background_tasks_spec.rb +2 -2
  65. data/spec/tools/cmd_tlm_server/interface_thread_spec.rb +4 -3
  66. data/spec/utilities/logger_spec.rb +3 -3
  67. data/test/performance/Rakefile +4 -4
  68. data/test/performance/config/data/crc.txt +67 -48
  69. metadata +2 -2
@@ -95,8 +95,6 @@ static VALUE line_clip_internal(double x0, double y0, double x1, double y1, doub
95
95
  volatile VALUE done = Qfalse;
96
96
  volatile VALUE clipped0 = Qfalse;
97
97
  volatile VALUE clipped1 = Qfalse;
98
- double x = 0.0;
99
- double y = 0.0;
100
98
 
101
99
  code0 = cal_code(x0, y0, xmin, ymin, xmax, ymax);
102
100
  code1 = cal_code(x1, y1, xmin, ymin, xmax, ymax);
@@ -117,8 +115,8 @@ static VALUE line_clip_internal(double x0, double y0, double x1, double y1, doub
117
115
  } else {
118
116
  /* Part of the line is inside the viewable area. Figure out which part
119
117
  * of the line can be drawn. */
120
- x = 0.0;
121
- y = 0.0;
118
+ double x;
119
+ double y;
122
120
 
123
121
  if (code0 != 0) {
124
122
  codeout = code0;
@@ -178,28 +176,19 @@ static VALUE line_clip(VALUE self, VALUE x0, VALUE y0, VALUE x1, VALUE y1, VALUE
178
176
  volatile VALUE result_clipped0 = Qnil;
179
177
  volatile VALUE result_clipped1 = Qnil;
180
178
  volatile VALUE return_value = Qnil;
181
- double double_x0 = 0.0;
182
- double double_y0 = 0.0;
183
- double double_x1 = 0.0;
184
- double double_y1 = 0.0;
185
- double double_xmin = 0.0;
186
- double double_ymin = 0.0;
187
- double double_xmax = 0.0;
188
- double double_ymax = 0.0;
179
+ double double_x0 = RFLOAT_VALUE(rb_funcall(x0, id_method_to_f, 0));
180
+ double double_y0 = RFLOAT_VALUE(rb_funcall(y0, id_method_to_f, 0));
181
+ double double_x1 = RFLOAT_VALUE(rb_funcall(x1, id_method_to_f, 0));
182
+ double double_y1 = RFLOAT_VALUE(rb_funcall(y1, id_method_to_f, 0));
183
+ double double_xmin = RFLOAT_VALUE(rb_funcall(xmin, id_method_to_f, 0));
184
+ double double_ymin = RFLOAT_VALUE(rb_funcall(ymin, id_method_to_f, 0));
185
+ double double_xmax = RFLOAT_VALUE(rb_funcall(xmax, id_method_to_f, 0));
186
+ double double_ymax = RFLOAT_VALUE(rb_funcall(ymax, id_method_to_f, 0));
189
187
  double result_x0 = 0.0;
190
188
  double result_y0 = 0.0;
191
189
  double result_x1 = 0.0;
192
190
  double result_y1 = 0.0;
193
191
 
194
- double_x0 = RFLOAT_VALUE(rb_funcall(x0, id_method_to_f, 0));
195
- double_y0 = RFLOAT_VALUE(rb_funcall(y0, id_method_to_f, 0));
196
- double_x1 = RFLOAT_VALUE(rb_funcall(x1, id_method_to_f, 0));
197
- double_y1 = RFLOAT_VALUE(rb_funcall(y1, id_method_to_f, 0));
198
- double_xmin = RFLOAT_VALUE(rb_funcall(xmin, id_method_to_f, 0));
199
- double_ymin = RFLOAT_VALUE(rb_funcall(ymin, id_method_to_f, 0));
200
- double_xmax = RFLOAT_VALUE(rb_funcall(xmax, id_method_to_f, 0));
201
- double_ymax = RFLOAT_VALUE(rb_funcall(ymax, id_method_to_f, 0));
202
-
203
192
  result = line_clip_internal(double_x0, double_y0, double_x1, double_y1, double_xmin, double_ymin, double_xmax, double_ymax, &result_x0, &result_y0, &result_x1, &result_y1, &result_clipped0, &result_clipped1);
204
193
 
205
194
  if (result == Qtrue)
@@ -236,10 +225,8 @@ static long scale_value_to_graph_y_internal (double y, double y_max, double y_sc
236
225
  static VALUE scale_value_to_graph_y(int argc, VALUE* argv, VALUE self) {
237
226
  volatile VALUE y = Qnil;
238
227
  ID id_axis = 0;
239
- long long_graph_top_y = 0;
240
- double double_y = 0.0;
241
- double double_y_max = 0.0;
242
- double double_y_scale = 0.0;
228
+ double double_y_max;
229
+ double double_y_scale;
243
230
 
244
231
  switch (argc) {
245
232
  case 1:
@@ -256,8 +243,8 @@ static VALUE scale_value_to_graph_y(int argc, VALUE* argv, VALUE self) {
256
243
  break;
257
244
  };
258
245
 
259
- long_graph_top_y = FIX2INT(rb_ivar_get(self, id_ivar_graph_top_y));
260
- double_y = RFLOAT_VALUE(rb_funcall(y, id_method_to_f, 0));
246
+ long long_graph_top_y = FIX2INT(rb_ivar_get(self, id_ivar_graph_top_y));
247
+ double double_y = RFLOAT_VALUE(rb_funcall(y, id_method_to_f, 0));
261
248
 
262
249
  if (id_axis == id_LEFT) {
263
250
  double_y_max = RFLOAT_VALUE(rb_funcall(rb_ivar_get(self, id_ivar_left_y_max), id_method_to_f, 0));
@@ -281,15 +268,10 @@ static long scale_value_to_graph_x_internal (double x, double x_min, double x_sc
281
268
  * This function converts an x value to an x coordinate on the graph
282
269
  */
283
270
  static VALUE scale_value_to_graph_x(VALUE self, VALUE x) {
284
- long long_graph_left_x = 0;
285
- double double_x = 0.0;
286
- double double_x_min = 0.0;
287
- double double_x_scale = 0.0;
288
-
289
- long_graph_left_x = FIX2INT(rb_ivar_get(self, id_ivar_graph_left_x));
290
- double_x = RFLOAT_VALUE(rb_funcall(x, id_method_to_f, 0));
291
- double_x_min = RFLOAT_VALUE(rb_funcall(rb_ivar_get(self, id_ivar_x_min), id_method_to_f, 0));
292
- double_x_scale = RFLOAT_VALUE(rb_funcall(rb_ivar_get(self, id_ivar_x_scale), id_method_to_f, 0));
271
+ long long_graph_left_x = FIX2INT(rb_ivar_get(self, id_ivar_graph_left_x));
272
+ double double_x = RFLOAT_VALUE(rb_funcall(x, id_method_to_f, 0));
273
+ double double_x_min = RFLOAT_VALUE(rb_funcall(rb_ivar_get(self, id_ivar_x_min), id_method_to_f, 0));
274
+ double double_x_scale = RFLOAT_VALUE(rb_funcall(rb_ivar_get(self, id_ivar_x_scale), id_method_to_f, 0));
293
275
 
294
276
  return INT2FIX(scale_value_to_graph_x_internal(double_x, double_x_min, double_x_scale, long_graph_left_x));
295
277
  }
@@ -301,10 +283,6 @@ static void draw_line_internal(VALUE dc, double x1, double y1, double x2, double
301
283
  volatile VALUE result = Qnil;
302
284
  volatile VALUE clipped1 = Qnil;
303
285
  volatile VALUE clipped2 = Qnil;
304
- long x1_scaled = 0;
305
- long y1_scaled = 0;
306
- long x2_scaled = 0;
307
- long y2_scaled = 0;
308
286
  double clipped_x1 = 0.0;
309
287
  double clipped_y1 = 0.0;
310
288
  double clipped_x2 = 0.0;
@@ -315,10 +293,10 @@ static void draw_line_internal(VALUE dc, double x1, double y1, double x2, double
315
293
 
316
294
  if (result == Qtrue) /* Line is visible so draw it */ {
317
295
  /* Scale to graph coordinates */
318
- x1_scaled = scale_value_to_graph_x_internal(clipped_x1, x_min, x_scale, graph_left_x);
319
- y1_scaled = scale_value_to_graph_y_internal(clipped_y1, y_max, y_scale, graph_top_y);
320
- x2_scaled = scale_value_to_graph_x_internal(clipped_x2, x_min, x_scale, graph_left_x);
321
- y2_scaled = scale_value_to_graph_y_internal(clipped_y2, y_max, y_scale, graph_top_y);
296
+ double x1_scaled = scale_value_to_graph_x_internal(clipped_x1, x_min, x_scale, graph_left_x);
297
+ double y1_scaled = scale_value_to_graph_y_internal(clipped_y1, y_max, y_scale, graph_top_y);
298
+ double x2_scaled = scale_value_to_graph_x_internal(clipped_x2, x_min, x_scale, graph_left_x);
299
+ double y2_scaled = scale_value_to_graph_y_internal(clipped_y2, y_max, y_scale, graph_top_y);
322
300
 
323
301
  /* Draw the line */
324
302
  if (RTEST(show_line)) {
@@ -339,30 +317,20 @@ static void draw_line_internal(VALUE dc, double x1, double y1, double x2, double
339
317
  * Draws a line between two points that is clipped to fit the visible graph if necessary
340
318
  */
341
319
  static VALUE draw_line(VALUE self, VALUE dc, VALUE x1, VALUE y1, VALUE x2, VALUE y2, VALUE show_line, VALUE point_size, VALUE axis, VALUE color) {
342
- long long_graph_left_x = 0;
343
- long long_graph_top_y = 0;
344
- ID id_axis = 0;
345
- double double_x1 = 0.0;
346
- double double_y1 = 0.0;
347
- double double_x2 = 0.0;
348
- double double_y2 = 0.0;
349
- double double_x_min = 0.0;
350
- double double_y_min = 0.0;
351
- double double_x_max = 0.0;
352
- double double_y_max = 0.0;
353
- double double_x_scale = 0.0;
354
- double double_y_scale = 0.0;
355
-
356
- id_axis = SYM2ID(axis);
357
- double_x_max = RFLOAT_VALUE(rb_funcall(rb_ivar_get(self, id_ivar_x_max), id_method_to_f, 0));
358
- double_x_min = RFLOAT_VALUE(rb_funcall(rb_ivar_get(self, id_ivar_x_min), id_method_to_f, 0));
359
- double_x1 = RFLOAT_VALUE(rb_funcall(x1, id_method_to_f, 0));
360
- double_y1 = RFLOAT_VALUE(rb_funcall(y1, id_method_to_f, 0));
361
- double_x2 = RFLOAT_VALUE(rb_funcall(x2, id_method_to_f, 0));
362
- double_y2 = RFLOAT_VALUE(rb_funcall(y2, id_method_to_f, 0));
363
- double_x_scale = RFLOAT_VALUE(rb_funcall(rb_ivar_get(self, id_ivar_x_scale), id_method_to_f, 0));
364
- long_graph_left_x = FIX2INT(rb_ivar_get(self, id_ivar_graph_left_x));
365
- long_graph_top_y = FIX2INT(rb_ivar_get(self, id_ivar_graph_top_y));
320
+ double double_y_min;
321
+ double double_y_max;
322
+ double double_y_scale;
323
+
324
+ ID id_axis = SYM2ID(axis);
325
+ double double_x_max = RFLOAT_VALUE(rb_funcall(rb_ivar_get(self, id_ivar_x_max), id_method_to_f, 0));
326
+ double double_x_min = RFLOAT_VALUE(rb_funcall(rb_ivar_get(self, id_ivar_x_min), id_method_to_f, 0));
327
+ double double_x1 = RFLOAT_VALUE(rb_funcall(x1, id_method_to_f, 0));
328
+ double double_y1 = RFLOAT_VALUE(rb_funcall(y1, id_method_to_f, 0));
329
+ double double_x2 = RFLOAT_VALUE(rb_funcall(x2, id_method_to_f, 0));
330
+ double double_y2 = RFLOAT_VALUE(rb_funcall(y2, id_method_to_f, 0));
331
+ double double_x_scale = RFLOAT_VALUE(rb_funcall(rb_ivar_get(self, id_ivar_x_scale), id_method_to_f, 0));
332
+ long long_graph_left_x = FIX2INT(rb_ivar_get(self, id_ivar_graph_left_x));
333
+ long long_graph_top_y = FIX2INT(rb_ivar_get(self, id_ivar_graph_top_y));
366
334
 
367
335
  if (id_axis == id_LEFT) {
368
336
  double_y_max = RFLOAT_VALUE(rb_funcall(rb_ivar_get(self, id_ivar_left_y_max), id_method_to_f, 0));
@@ -383,37 +351,28 @@ static VALUE draw_line(VALUE self, VALUE dc, VALUE x1, VALUE y1, VALUE x2, VALUE
383
351
  * Draws all lines for the given axis
384
352
  */
385
353
  static VALUE draw_lines (VALUE self, VALUE dc, VALUE axis) {
386
- long long_graph_left_x = 0;
387
- long long_graph_top_y = 0;
388
- long num_lines = 0;
389
354
  long line_index = 0;
390
355
  long line_length = 0;
391
356
  long point_index = 0;
392
- ID id_axis = 0;
393
357
  volatile VALUE lines = Qnil;
394
358
  volatile VALUE line = Qnil;
395
359
  volatile VALUE x_values = Qnil;
396
360
  volatile VALUE y_values = Qnil;
397
361
  volatile VALUE color = Qnil;
398
- volatile VALUE show_lines = Qnil;
399
- volatile VALUE point_size = Qnil;
400
- double double_x1 = 0.0;
401
- double double_y1 = 0.0;
402
- double double_x2 = 0.0;
403
- double double_y2 = 0.0;
404
- double double_x_min = 0.0;
405
- double double_y_min = 0.0;
406
- double double_x_max = 0.0;
407
- double double_y_max = 0.0;
408
- double double_x_scale = 0.0;
409
- double double_y_scale = 0.0;
410
-
411
- id_axis = SYM2ID(axis);
412
- double_x_max = RFLOAT_VALUE(rb_funcall(rb_ivar_get(self, id_ivar_x_max), id_method_to_f, 0));
413
- double_x_min = RFLOAT_VALUE(rb_funcall(rb_ivar_get(self, id_ivar_x_min), id_method_to_f, 0));
414
- double_x_scale = RFLOAT_VALUE(rb_funcall(rb_ivar_get(self, id_ivar_x_scale), id_method_to_f, 0));
415
- long_graph_left_x = FIX2INT(rb_ivar_get(self, id_ivar_graph_left_x));
416
- long_graph_top_y = FIX2INT(rb_ivar_get(self, id_ivar_graph_top_y));
362
+ double double_x1;
363
+ double double_y1;
364
+ double double_x2;
365
+ double double_y2;
366
+ double double_y_min;
367
+ double double_y_max;
368
+ double double_y_scale;
369
+
370
+ ID id_axis = SYM2ID(axis);
371
+ double double_x_max = RFLOAT_VALUE(rb_funcall(rb_ivar_get(self, id_ivar_x_max), id_method_to_f, 0));
372
+ double double_x_min = RFLOAT_VALUE(rb_funcall(rb_ivar_get(self, id_ivar_x_min), id_method_to_f, 0));
373
+ double double_x_scale = RFLOAT_VALUE(rb_funcall(rb_ivar_get(self, id_ivar_x_scale), id_method_to_f, 0));
374
+ long long_graph_left_x = FIX2INT(rb_ivar_get(self, id_ivar_graph_left_x));
375
+ long long_graph_top_y = FIX2INT(rb_ivar_get(self, id_ivar_graph_top_y));
417
376
 
418
377
  if (id_axis == id_LEFT) {
419
378
  lines = rb_funcall(rb_ivar_get(self, id_ivar_lines), id_method_left, 0);
@@ -427,10 +386,10 @@ static VALUE draw_lines (VALUE self, VALUE dc, VALUE axis) {
427
386
  double_y_scale = RFLOAT_VALUE(rb_funcall(rb_ivar_get(self, id_ivar_right_y_scale), id_method_to_f, 0));
428
387
  }
429
388
 
430
- show_lines = rb_ivar_get(self, id_ivar_show_lines);
431
- point_size = rb_ivar_get(self, id_ivar_point_size);
389
+ volatile VALUE show_lines = rb_ivar_get(self, id_ivar_show_lines);
390
+ volatile VALUE point_size = rb_ivar_get(self, id_ivar_point_size);
432
391
 
433
- num_lines = RARRAY_LEN(lines);
392
+ long num_lines = RARRAY_LEN(lines);
434
393
  for (line_index = 0; line_index < num_lines; line_index++) {
435
394
  line = rb_ary_entry(lines, line_index);
436
395
  x_values = rb_ary_entry(line, 0);
@@ -23,31 +23,64 @@ VALUE cSegFault = Qnil;
23
23
  #include <signal.h>
24
24
  #include <unistd.h>
25
25
  #include <time.h>
26
+ #include <string.h>
27
+ #include <sys/stat.h>
26
28
 
27
29
  static void catch_sigsegv(int sig_num) {
30
+ const int FILENAME_LEN = 256;
28
31
  char *cosmos_log_dir = NULL;
29
32
  time_t rawtime;
30
- struct tm *timeinfo;
31
- char filename[256];
33
+ struct tm timeinfo;
34
+ struct tm *timeinfo_ptr;
35
+ struct stat stats;
36
+ char filename[FILENAME_LEN];
32
37
  FILE* file = NULL;
33
38
 
34
39
  signal(SIGSEGV, SIG_DFL);
35
40
  signal(SIGILL, SIG_DFL);
36
41
 
37
42
  cosmos_log_dir = getenv("COSMOS_LOGS_DIR");
38
- if (cosmos_log_dir == NULL) {
39
- cosmos_log_dir = (char*) ".";
43
+ // If the COSMOS_LOGS_DIR env var isn't set or if it's too big set to "."
44
+ // NOTE: The filename buffer will be written to by snprintf which appends
45
+ // a null terminator so we have 1 less byte available minus the length
46
+ // of the fixed filename structure
47
+ if ((cosmos_log_dir == NULL) || (strlen(cosmos_log_dir) > (FILENAME_LEN - 1 - strlen("/YYYY_MM_DD_HH_MM_SS_segfault.txt"))))
48
+ {
49
+ cosmos_log_dir = (char*)".";
40
50
  }
51
+ // Validate that we can write to this directory
52
+ if (stat(cosmos_log_dir, &stats) == 0)
53
+ {
54
+ if (!((stats.st_mode & W_OK)&& S_ISDIR(stats.st_mode)))
55
+ {
56
+ cosmos_log_dir = (char *)".";
57
+ }
58
+ }
59
+ else
60
+ {
61
+ cosmos_log_dir = (char *)".";
62
+ }
63
+
41
64
  time(&rawtime);
42
- timeinfo = localtime(&rawtime);
43
- sprintf(filename, "%s/%04u_%02u_%02u_%02u_%02u_%02u_segfault.txt",
44
- cosmos_log_dir,
45
- 1900 + timeinfo->tm_year,
46
- 1 + timeinfo->tm_mon,
47
- timeinfo->tm_mday,
48
- timeinfo->tm_hour,
49
- timeinfo->tm_min,
50
- timeinfo->tm_sec);
65
+ timeinfo_ptr = localtime_r(&rawtime, &timeinfo);
66
+ if (timeinfo_ptr == NULL)
67
+ {
68
+ // If localtime returns NULL we set our own and set to 1919 to make it interesting
69
+ strptime("1919-01-01 00:00:00", "%Y-%m-%d %H:%M:%S", &timeinfo);
70
+ }
71
+ snprintf(filename, FILENAME_LEN, "%s/%04u_%02u_%02u_%02u_%02u_%02u_segfault.txt",
72
+ cosmos_log_dir,
73
+ 1900 + timeinfo.tm_year,
74
+ 1 + timeinfo.tm_mon,
75
+ timeinfo.tm_mday,
76
+ timeinfo.tm_hour,
77
+ timeinfo.tm_min,
78
+ timeinfo.tm_sec);
79
+
80
+ // Fortify warns about Path Manipulation here. We explictly allow this to let
81
+ // segfault files be written to a directory of their choosing.
82
+ // The input is validated above for length and to ensure it is a writable directory.
83
+ // If the checks fail the directory is set to the current directory without additional info.
51
84
  file = freopen(filename, "a", stderr);
52
85
  /* Using file removes a warning */
53
86
  if (file) {
@@ -58,11 +91,12 @@ VALUE cSegFault = Qnil;
58
91
  }
59
92
  #endif
60
93
 
61
- static VALUE segfault(VALUE self) {
62
- char *a = 0;
63
- *a = 50;
64
- return Qnil;
65
- }
94
+ /* NOTE: Uncomment and rebuilt for testing the handler */
95
+ // static VALUE segfault(VALUE self) {
96
+ // char *a = 0;
97
+ // *a = 50;
98
+ // return Qnil;
99
+ // }
66
100
 
67
101
  /*
68
102
  * Initialize methods for Platform specific C code
@@ -95,7 +129,8 @@ void Init_platform (void) {
95
129
  signal(SIGILL, catch_sigsegv);
96
130
  #endif
97
131
 
98
- mCosmos = rb_define_module("Cosmos");
99
- cSegFault = rb_define_class_under(mCosmos, "SegFault", rb_cObject);
100
- rb_define_singleton_method(cSegFault, "segfault", segfault, 0);
132
+ /* NOTE: Uncomment and rebuilt for testing the handler */
133
+ // mCosmos = rb_define_module("Cosmos");
134
+ // cSegFault = rb_define_class_under(mCosmos, "SegFault", rb_cObject);
135
+ // rb_define_singleton_method(cSegFault, "segfault", segfault, 0);
101
136
  }
@@ -30,20 +30,16 @@ static ID id_method_to_f = 0;
30
30
  */
31
31
  static VALUE polynomial_conversion_call(VALUE self, VALUE value, VALUE myself, VALUE buffer)
32
32
  {
33
- volatile VALUE coeffs = Qnil;
34
- long coeffs_length = 0;
35
33
  int index = 0;
36
- double double_value = 0.0;
37
- double coeff = 0.0;
38
34
  double converted = 0.0;
39
35
  double raised_to_power = 1.0;
40
36
 
41
- coeffs = rb_ivar_get(self, id_ivar_coeffs);
42
- coeffs_length = RARRAY_LEN(coeffs);
43
- double_value = RFLOAT_VALUE(rb_funcall(value, id_method_to_f, 0));
37
+ volatile VALUE coeffs = rb_ivar_get(self, id_ivar_coeffs);
38
+ long coeffs_length = RARRAY_LEN(coeffs);
39
+ double double_value = RFLOAT_VALUE(rb_funcall(value, id_method_to_f, 0));
44
40
 
45
41
  /* Handle C0 */
46
- coeff = RFLOAT_VALUE(rb_ary_entry(coeffs, 0));
42
+ double coeff = RFLOAT_VALUE(rb_ary_entry(coeffs, 0));
47
43
  converted += coeff;
48
44
 
49
45
  /* Handle Coefficients raised to a power */
@@ -493,6 +493,9 @@ static VALUE binary_accessor_read(VALUE self, VALUE param_bit_offset, VALUE para
493
493
  if (BYTE_ALIGNED(bit_offset)) {
494
494
  string_length = upper_bound - lower_bound + 1;
495
495
  string = malloc(string_length + 1);
496
+ if (string == NULL) {
497
+ rb_raise(rb_eNoMemError, "malloc of %d returned NULL", string_length + 1);
498
+ }
496
499
  memcpy(string, buffer + lower_bound, string_length);
497
500
  string[string_length] = 0;
498
501
  if (param_data_type == symbol_STRING) {
@@ -538,6 +541,9 @@ static VALUE binary_accessor_read(VALUE self, VALUE param_bit_offset, VALUE para
538
541
  string_length = ((bit_size - 1)/ 8) + 1;
539
542
  array_length = string_length + 4; /* Required number of bytes plus slack */
540
543
  unsigned_char_array = (unsigned char*) malloc(array_length);
544
+ if (unsigned_char_array == NULL) {
545
+ rb_raise(rb_eNoMemError, "malloc of %d returned NULL", array_length);
546
+ }
541
547
  read_bitfield(lower_bound, upper_bound, bit_offset, bit_size, given_bit_offset, given_bit_size, param_endianness, buffer, (int)buffer_length, unsigned_char_array);
542
548
 
543
549
  num_words = ((string_length - 1) / 4) + 1;
@@ -629,6 +635,9 @@ static VALUE binary_accessor_read(VALUE self, VALUE param_bit_offset, VALUE para
629
635
  string_length = ((bit_size - 1)/ 8) + 1;
630
636
  array_length = string_length + 4; /* Required number of bytes plus slack */
631
637
  unsigned_char_array = (unsigned char*) malloc(array_length);
638
+ if (unsigned_char_array == NULL) {
639
+ rb_raise(rb_eNoMemError, "malloc of %d returned NULL", array_length);
640
+ }
632
641
  read_bitfield(lower_bound, upper_bound, bit_offset, bit_size, given_bit_offset, given_bit_size, param_endianness, buffer, (int)buffer_length, unsigned_char_array);
633
642
 
634
643
  num_words = ((string_length - 1) / 4) + 1;
@@ -1001,6 +1010,9 @@ static VALUE binary_accessor_write(VALUE self, VALUE value, VALUE param_bit_offs
1001
1010
  string_length = ((bit_size - 1)/ 8) + 1;
1002
1011
  array_length = string_length + 4; /* Required number of bytes plus slack */
1003
1012
  unsigned_char_array = (unsigned char*) malloc(array_length);
1013
+ if (unsigned_char_array == NULL) {
1014
+ rb_raise(rb_eNoMemError, "malloc of %d returned NULL", array_length);
1015
+ }
1004
1016
 
1005
1017
  num_words = ((string_length - 1) / 4) + 1;
1006
1018
  num_bytes = num_words * 4;
data/install/Rakefile CHANGED
@@ -39,14 +39,14 @@ def create_crc_file(official)
39
39
  crc = Cosmos::Crc32.new(Cosmos::Crc32::DEFAULT_POLY, Cosmos::Crc32::DEFAULT_SEED, true, false)
40
40
  File.open("config/data/crc.txt",'w') do |file|
41
41
  file.puts "USER_MODIFIED" unless official
42
- Dir[File.join('lib','**','*')].each do |filename|
42
+ Dir[File.join('lib','**','*')].sort.each do |filename|
43
43
  next if File.directory?(filename)
44
44
  next if ignore.include?(filename)
45
45
  file_data = File.open(filename, 'rb').read.gsub("\x0D\x0A", "\x0A")
46
46
  file.puts "\"#{filename}\" #{sprintf("0x%08X", crc.calc(file_data))}"
47
47
  count += 1
48
48
  end
49
- Dir[File.join('config','**','*')].each do |filename|
49
+ Dir[File.join('config','**','*')].sort.each do |filename|
50
50
  next if File.directory?(filename)
51
51
  next if ignore.include?(filename)
52
52
  next if File.basename(filename) == 'crc.txt'
@@ -54,14 +54,14 @@ def create_crc_file(official)
54
54
  file.puts "\"#{filename}\" #{sprintf("0x%08X", crc.calc(file_data))}"
55
55
  count += 1
56
56
  end
57
- Dir[File.join('tools','**','*')].each do |filename|
57
+ Dir[File.join('tools','**','*')].sort.each do |filename|
58
58
  next if File.directory?(filename)
59
59
  next if ignore.include?(filename)
60
60
  file_data = File.open(filename, 'rb').read.gsub("\x0D\x0A", "\x0A")
61
61
  file.puts "\"#{filename}\" #{sprintf("0x%08X", crc.calc(file_data))}"
62
62
  count += 1
63
63
  end
64
- Dir[File.join('procedures','**','*')].each do |filename|
64
+ Dir[File.join('procedures','**','*')].sort.each do |filename|
65
65
  next if File.directory?(filename)
66
66
  next if ignore.include?(filename)
67
67
  file_data = File.open(filename, 'rb').read.gsub("\x0D\x0A", "\x0A")