- Notifications
You must be signed in to change notification settings - Fork4.9k
Commit7ecdeb5
committed
Fix over-allocation of space for array_out()'s result string.
array_out overestimated the space needed for its output, possibly bya very substantial amount if the array is multi-dimensional, becauseof wrong order of operations in the loop that counts the number ofcurly-brace pairs needed. While the output string is normallyshort-lived, this could still cause problems in extreme cases.An additional minor error was that it counted one more delimiter thanis actually needed.Repair those errors, add an Assert that the space is now correctlycalculated, and make some minor improvements in the comments.I also failed to resist the temptation to get rid of an integermodulus operation per array element; a simple comparison is sufficient.This bug dates clear back to Berkeley days, so back-patch to allsupported versions.Keiichi Hirobe, minor additional work by meDiscussion:https://postgr.es/m/CAH=EFxE9W0tRvQkixR2XJRRCToUYUEDkJZk6tnADXugPBRdcdg@mail.gmail.com1 parent402da70 commit7ecdeb5
1 file changed
+22
-10
lines changedLines changed: 22 additions & 10 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
976 | 976 |
| |
977 | 977 |
| |
978 | 978 |
| |
| 979 | + | |
979 | 980 |
| |
980 |
| - | |
981 | 981 |
| |
982 | 982 |
| |
983 | 983 |
| |
| |||
1050 | 1050 |
| |
1051 | 1051 |
| |
1052 | 1052 |
| |
1053 |
| - | |
| 1053 | + | |
1054 | 1054 |
| |
1055 | 1055 |
| |
1056 | 1056 |
| |
| |||
1105 | 1105 |
| |
1106 | 1106 |
| |
1107 | 1107 |
| |
1108 |
| - | |
| 1108 | + | |
1109 | 1109 |
| |
1110 | 1110 |
| |
1111 | 1111 |
| |
| |||
1121 | 1121 |
| |
1122 | 1122 |
| |
1123 | 1123 |
| |
1124 |
| - | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
1125 | 1128 |
| |
1126 | 1129 |
| |
1127 |
| - | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
1128 | 1134 |
| |
| 1135 | + | |
1129 | 1136 |
| |
1130 |
| - | |
1131 |
| - | |
1132 | 1137 |
| |
1133 | 1138 |
| |
1134 | 1139 |
| |
| |||
1140 | 1145 |
| |
1141 | 1146 |
| |
1142 | 1147 |
| |
| 1148 | + | |
1143 | 1149 |
| |
1144 | 1150 |
| |
1145 |
| - | |
| 1151 | + | |
| 1152 | + | |
1146 | 1153 |
| |
1147 | 1154 |
| |
1148 | 1155 |
| |
| |||
1180 | 1187 |
| |
1181 | 1188 |
| |
1182 | 1189 |
| |
1183 |
| - | |
1184 |
| - | |
| 1190 | + | |
1185 | 1191 |
| |
1186 | 1192 |
| |
1187 | 1193 |
| |
1188 | 1194 |
| |
1189 | 1195 |
| |
| 1196 | + | |
| 1197 | + | |
1190 | 1198 |
| |
| 1199 | + | |
1191 | 1200 |
| |
1192 | 1201 |
| |
1193 | 1202 |
| |
1194 | 1203 |
| |
1195 | 1204 |
| |
1196 | 1205 |
| |
1197 | 1206 |
| |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
1198 | 1210 |
| |
1199 | 1211 |
| |
1200 | 1212 |
| |
|
0 commit comments
Comments
(0)