about summary refs log tree commit diff stats
path: root/edit/005-sandbox.mu
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2017-06-22 11:35:22 -0700
committerKartik K. Agaram <vc@akkartik.com>2017-06-22 11:35:22 -0700
commitbde85557ac92d30564ce17ae1f5b5924e88982d9 (patch)
tree8224fd4fd2c058c9141ac19d0fa4b7180ee9f477 /edit/005-sandbox.mu
parente80fd05f4e02c930d5709068267ea4a58e54229d (diff)
downloadmu-bde85557ac92d30564ce17ae1f5b5924e88982d9.tar.gz
3938
Fix an out-of-bounds write to the screen when sandboxes aligned just
right.

Thanks Ella Couch for reporting this issue.
Diffstat (limited to 'edit/005-sandbox.mu')
-rw-r--r--edit/005-sandbox.mu34
1 files changed, 32 insertions, 2 deletions
diff --git a/edit/005-sandbox.mu b/edit/005-sandbox.mu
index ae322545..2be439e3 100644
--- a/edit/005-sandbox.mu
+++ b/edit/005-sandbox.mu
@@ -272,13 +272,13 @@ def render-sandboxes screen:&:screen, sandbox:&:sandbox, left:num, right:num, ro
   load-ingredients
   return-unless sandbox
   screen-height:num <- screen-height screen
-  at-bottom?:bool <- greater-or-equal row, screen-height
-  return-if at-bottom?
   hidden?:bool <- lesser-than idx, render-from
   {
     break-if hidden?
     # render sandbox menu
     row <- add row, 1
+    at-bottom?:bool <- greater-or-equal row, screen-height
+    return-if at-bottom?
     screen <- move-cursor screen, row, left
     screen <- render-sandbox-menu screen, idx, left, right
     # save menu row so we can detect clicks to it later
@@ -340,6 +340,36 @@ def render-sandbox-menu screen:&:screen, sandbox-index:num, left:num, right:num
   clear-line-until screen, right, 52/background-red
 ]
 
+scenario skip-rendering-sandbox-menu-past-bottom-row [
+  trace-until 100/app  # trace too long
+  assume-screen 100/width, 7/height
+  # recipe editor is empty
+  assume-resources [
+  ]
+  # create two sandboxes such that the top one just barely fills the screen
+  env:&:environment <- new-programming-environment resources, screen, []
+  render-all screen, env, render
+  assume-console [
+    left-click 1, 75
+    type [add 1, 1]
+    press F4
+    type [add 2, 2]
+    press F4
+  ]
+  run [
+    event-loop screen, console, env, resources
+  ]
+  screen-should-contain [
+    .                                                                                 run (F4)           .
+    .                                                  ┊                                                 .
+    .┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┈┊─────────────────────────────────────────────────.
+    .                                                  ┊0   edit       copy       to recipe    delete    .
+    .                                                  ┊add 2, 2                                         .
+    .                                                  ┊4                                                .
+    .                                                  ┊─────────────────────────────────────────────────.
+  ]
+]
+
 # divide up the menu bar for a sandbox into 3 segments, for edit/copy/delete buttons
 # delete-button-right == right
 # all left/right pairs are inclusive