pathmeasure.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright 2018 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #include "include/core/SkCanvas.h"
  8. #include "include/core/SkPaint.h"
  9. #include "include/core/SkPath.h"
  10. #include "include/core/SkPathEffect.h"
  11. #include "include/core/SkTypes.h"
  12. #include "include/effects/SkDashPathEffect.h"
  13. // Repro case for skia:7674. Requires lots of RAM to run, and currently triggers UB:
  14. // ../include/private/SkTDArray.h:382:26:
  15. // runtime error: signed integer overflow: 2147483644 + 4 cannot be represented in type 'int'
  16. static SK_UNUSED void path_measure_explosion(SkCanvas* canvas) {
  17. SkPaint p;
  18. p.setAntiAlias(false);
  19. float intervals[] = { 0, 10e9f };
  20. p.setStyle(SkPaint::kStroke_Style);
  21. p.setPathEffect(SkDashPathEffect::Make(intervals, SK_ARRAY_COUNT(intervals), 0));
  22. int quadratic_at[] = {
  23. 13, 68, 258, 1053, 1323, 2608, 10018, 15668, 59838, 557493, 696873, 871098, 4153813,
  24. 15845608, 48357008, 118059138, 288230353, 360287948, 562949933, 703687423, 1099511613, 0
  25. };
  26. int next_quadratic_at = 0;
  27. SkPath path;
  28. path.moveTo(0, 0);
  29. int i = 1;
  30. for (int points = 1; points < 2147483647; ) {
  31. if (points == quadratic_at[next_quadratic_at]) {
  32. path.quadTo(i, 0, i, 0);
  33. next_quadratic_at++;
  34. points += 2;
  35. } else {
  36. path.lineTo(i, 0);
  37. points += 1;
  38. }
  39. i++;
  40. if (i == 1000000) {
  41. path.moveTo(0, 0);
  42. points += 1;
  43. i = 1;
  44. }
  45. }
  46. canvas->drawPath(path, p);
  47. }
  48. #if 0
  49. #include "gm/gm.h"
  50. DEF_SIMPLE_GM(PathMeasure_explosion, canvas, 500,500) {
  51. path_measure_explosion(canvas);
  52. }
  53. #endif