From 6d0633ea539ac7616611c49716387ac31f5cc976 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Fri, 19 Jun 2015 18:25:31 -0700 Subject: 1602 I forgot to check for nulls before writing prev pointers in doubly linked lists. Tests were accidentally passing. --- 065duplex_list.mu | 52 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 31 insertions(+), 21 deletions(-) diff --git a/065duplex_list.mu b/065duplex_list.mu index 287e460b..0bcda1b9 100644 --- a/065duplex_list.mu +++ b/065duplex_list.mu @@ -16,6 +16,7 @@ recipe push-duplex [ val:address:location/deref <- copy x:location next:address:address:duplex-list <- get-address result:address:duplex-list/deref, next:offset next:address:address:duplex-list/deref <- copy in:address:duplex-list + reply-unless in:address:duplex-list, result:address:duplex-list prev:address:address:duplex-list <- get-address in:address:duplex-list/deref, prev:offset prev:address:address:duplex-list/deref <- copy result:address:duplex-list reply result:address:duplex-list @@ -25,6 +26,7 @@ recipe push-duplex [ recipe first-duplex [ default-space:address:array:location <- new location:type, 30:literal in:address:duplex-list <- next-ingredient + reply-unless in:address:duplex-list, 0:literal result:location <- get in:address:duplex-list/deref, value:offset reply result:location ] @@ -33,6 +35,7 @@ recipe first-duplex [ recipe next-duplex [ default-space:address:array:location <- new location:type, 30:literal in:address:duplex-list <- next-ingredient + reply-unless in:address:duplex-list, 0:literal result:address:duplex-list <- get in:address:duplex-list/deref, next:offset reply result:address:duplex-list ] @@ -41,35 +44,42 @@ recipe next-duplex [ recipe prev-duplex [ default-space:address:array:location <- new location:type, 30:literal in:address:duplex-list <- next-ingredient + reply-unless in:address:duplex-list, 0:literal result:address:duplex-list <- get in:address:duplex-list/deref, prev:offset reply result:address:duplex-list ] scenario duplex-list-handling [ run [ - 1:address:duplex-list <- copy 0:literal - 1:address:duplex-list <- push-duplex 3:literal, 1:address:duplex-list - 1:address:duplex-list <- push-duplex 4:literal, 1:address:duplex-list - 1:address:duplex-list <- push-duplex 5:literal, 1:address:duplex-list - 2:address:duplex-list <- copy 1:address:duplex-list - 3:number <- first 2:address:duplex-list - 2:address:duplex-list <- next-duplex 2:address:duplex-list - 4:number <- first 2:address:duplex-list - 2:address:duplex-list <- next-duplex 2:address:duplex-list - 5:number <- first 2:address:duplex-list - 2:address:duplex-list <- prev-duplex 2:address:duplex-list - 6:number <- first 2:address:duplex-list - 2:address:duplex-list <- prev-duplex 2:address:duplex-list - 7:number <- first 2:address:duplex-list - 8:boolean <- equal 1:address:duplex-list, 2:address:duplex-list + # reserve locations 0, 1 and 2 to check for missing null check + 1:number <- copy 34:literal + 2:number <- copy 35:literal + 3:address:duplex-list <- copy 0:literal + 3:address:duplex-list <- push-duplex 3:literal, 3:address:duplex-list + 3:address:duplex-list <- push-duplex 4:literal, 3:address:duplex-list + 3:address:duplex-list <- push-duplex 5:literal, 3:address:duplex-list + 4:address:duplex-list <- copy 3:address:duplex-list + 5:number <- first 4:address:duplex-list + 4:address:duplex-list <- next-duplex 4:address:duplex-list + 6:number <- first 4:address:duplex-list + 4:address:duplex-list <- next-duplex 4:address:duplex-list + 7:number <- first 4:address:duplex-list + 4:address:duplex-list <- prev-duplex 4:address:duplex-list + 8:number <- first 4:address:duplex-list + 4:address:duplex-list <- prev-duplex 4:address:duplex-list + 9:number <- first 4:address:duplex-list + 10:boolean <- equal 3:address:duplex-list, 4:address:duplex-list +#? $dump-trace #? 1 ] memory-should-contain [ - 3 <- 5 # scanning next - 4 <- 4 - 5 <- 3 - 6 <- 4 # then prev - 7 <- 5 - 8 <- 1 # list back at start + 1 <- 34 + 2 <- 35 + 5 <- 5 # scanning next + 6 <- 4 + 7 <- 3 + 8 <- 4 # then prev + 9 <- 5 + 10 <- 1 # list back at start ] ] -- cgit 1.4.1-2-gfad0 51' href='#n51'>51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242