- Notifications
You must be signed in to change notification settings - Fork4.9k
Commit600b953
committed
Clean up formatting.c's logic for matching constant strings.
seq_search(), which is used to match input substrings to constantssuch as month and day names, had a lot of bizarre and unnecessarybehaviors. It was mostly possible to avert our eyes from that before,but we don't want to duplicate those behaviors in the upcoming patchto allow recognition of non-English month and day names. So it's timeto clean this up. In particular:* seq_search scribbled on the input string, which is a pretty dangerousthing to do, especially in the badly underdocumented way it was done here.Fortunately the input string is a temporary copy, but that was being madethree subroutine levels away, making it something easy to breakaccidentally. The behavior is externally visible nonetheless, in the formof odd case-folding in error reports about unrecognized month/day names.The scribbling is evidently being done to save a few calls to pg_tolower,but that's such a cheap function (at least for ASCII data) that it'spretty pointless to worry about. In HEAD I switched it to bepg_ascii_tolower to ensure it is cheap in all cases; but there are cornercases in Turkish where this'd change behavior, so leave it as pg_tolowerin the back branches.* seq_search insisted on knowing the case form (all-upper, all-lower,or initcap) of the constant strings, so that it didn't have to case-foldthem to perform case-insensitive comparisons. This likewise seems likeexcessive micro-optimization, given that pg_tolower is certainly verycheap for ASCII data. It seems unsafe to assume that we know the caseform that will come out of pg_locale.c for localized month/day names, soit's better just to define the comparison rule as "downcase all stringsbefore comparing". (The choice between downcasing and upcasing isarbitrary so far as English is concerned, but it might not be in otherlocales, so follow citext's lead here.)* seq_search also had a parameter that'd cause it to report a matchafter a maximum number of characters, even if the constant string werelonger than that. This was not actually used because no caller passeda value small enough to cut off a comparison. Replicating that behaviorfor localized month/day names seems expensive as well as useless, solet's get rid of that too.* from_char_seq_search used the maximum-length parameter to truncatethe input string in error reports about not finding a matching name.This leads to rather confusing reports in many cases. Worse, it isoutright dangerous if the input string isn't all-ASCII, because werisk truncating the string in the middle of a multibyte character.That'd lead either to delivering an illegible error message to theclient, or to encoding-conversion failures that obscure the actualdata problem. Get rid of that in favor of truncating at whitespaceif any (a suggestion due to Alvaro Herrera).In addition to fixing these things, I const-ified the input stringpointers of DCH_from_char and its subroutines, to make sure therearen't any other scribbling-on-input problems.The risk of generating a badly-encoded error message seems likeenough of a bug to justify back-patching, so patch all supportedbranches.Discussion:https://postgr.es/m/29432.1579731087@sss.pgh.pa.us1 parentd76652e commit600b953
File tree
2 files changed
+85
-91
lines changed- src
- backend/utils/adt
- test/regress/expected
2 files changed
+85
-91
lines changedLines changed: 84 additions & 90 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
84 | 84 |
| |
85 | 85 |
| |
86 | 86 |
| |
| 87 | + | |
87 | 88 |
| |
88 | 89 |
| |
89 | 90 |
| |
| |||
280 | 281 |
| |
281 | 282 |
| |
282 | 283 |
| |
283 |
| - | |
284 |
| - | |
285 |
| - | |
286 |
| - | |
287 |
| - | |
288 |
| - | |
289 |
| - | |
290 |
| - | |
291 |
| - | |
292 |
| - | |
293 |
| - | |
294 |
| - | |
295 | 284 |
| |
296 | 285 |
| |
297 | 286 |
| |
| |||
953 | 942 |
| |
954 | 943 |
| |
955 | 944 |
| |
956 |
| - | |
| 945 | + | |
957 | 946 |
| |
958 | 947 |
| |
959 | 948 |
| |
| |||
963 | 952 |
| |
964 | 953 |
| |
965 | 954 |
| |
966 |
| - | |
| 955 | + | |
967 | 956 |
| |
968 | 957 |
| |
969 |
| - | |
970 |
| - | |
971 |
| - | |
972 |
| - | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
973 | 964 |
| |
974 | 965 |
| |
975 | 966 |
| |
| |||
2083 | 2074 |
| |
2084 | 2075 |
| |
2085 | 2076 |
| |
2086 |
| - | |
| 2077 | + | |
2087 | 2078 |
| |
2088 | 2079 |
| |
2089 | 2080 |
| |
| |||
2157 | 2148 |
| |
2158 | 2149 |
| |
2159 | 2150 |
| |
2160 |
| - | |
| 2151 | + | |
2161 | 2152 |
| |
2162 | 2153 |
| |
2163 | 2154 |
| |
2164 |
| - | |
| 2155 | + | |
2165 | 2156 |
| |
2166 | 2157 |
| |
2167 | 2158 |
| |
| |||
2178 | 2169 |
| |
2179 | 2170 |
| |
2180 | 2171 |
| |
| 2172 | + | |
| 2173 | + | |
2181 | 2174 |
| |
2182 |
| - | |
| 2175 | + | |
| 2176 | + | |
2183 | 2177 |
| |
2184 | 2178 |
| |
2185 | 2179 |
| |
| |||
2247 | 2241 |
| |
2248 | 2242 |
| |
2249 | 2243 |
| |
2250 |
| - | |
| 2244 | + | |
2251 | 2245 |
| |
2252 | 2246 |
| |
2253 | 2247 |
| |
2254 | 2248 |
| |
2255 |
| - | |
2256 |
| - | |
2257 |
| - | |
| 2249 | + | |
| 2250 | + | |
| 2251 | + | |
| 2252 | + | |
| 2253 | + | |
| 2254 | + | |
| 2255 | + | |
| 2256 | + | |
| 2257 | + | |
| 2258 | + | |
2258 | 2259 |
| |
2259 | 2260 |
| |
2260 |
| - | |
| 2261 | + | |
2261 | 2262 |
| |
2262 |
| - | |
2263 |
| - | |
2264 |
| - | |
2265 |
| - | |
2266 |
| - | |
| 2263 | + | |
| 2264 | + | |
2267 | 2265 |
| |
2268 | 2266 |
| |
2269 | 2267 |
| |
| 2268 | + | |
2270 | 2269 |
| |
2271 | 2270 |
| |
2272 | 2271 |
| |
2273 |
| - | |
2274 |
| - | |
2275 |
| - | |
2276 |
| - | |
2277 |
| - | |
| 2272 | + | |
| 2273 | + | |
2278 | 2274 |
| |
2279 |
| - | |
| 2275 | + | |
2280 | 2276 |
| |
| 2277 | + | |
| 2278 | + | |
| 2279 | + | |
2281 | 2280 |
| |
2282 |
| - | |
| 2281 | + | |
2283 | 2282 |
| |
2284 | 2283 |
| |
2285 |
| - | |
| 2284 | + | |
| 2285 | + | |
2286 | 2286 |
| |
2287 |
| - | |
2288 |
| - | |
2289 |
| - | |
2290 |
| - | |
2291 |
| - | |
2292 |
| - | |
2293 |
| - | |
| 2287 | + | |
2294 | 2288 |
| |
2295 | 2289 |
| |
2296 |
| - | |
| 2290 | + | |
2297 | 2291 |
| |
2298 | 2292 |
| |
2299 |
| - | |
| 2293 | + | |
2300 | 2294 |
| |
2301 | 2295 |
| |
2302 |
| - | |
2303 |
| - | |
2304 |
| - | |
2305 |
| - | |
2306 |
| - | |
2307 |
| - | |
2308 |
| - | |
2309 |
| - | |
2310 |
| - | |
2311 |
| - | |
2312 |
| - | |
2313 |
| - | |
2314 |
| - | |
2315 |
| - | |
2316 |
| - | |
2317 |
| - | |
2318 |
| - | |
2319 |
| - | |
| 2296 | + | |
| 2297 | + | |
| 2298 | + | |
2320 | 2299 |
| |
2321 | 2300 |
| |
2322 | 2301 |
| |
| |||
2325 | 2304 |
| |
2326 | 2305 |
| |
2327 | 2306 |
| |
2328 |
| - | |
2329 |
| - | |
| 2307 | + | |
| 2308 | + | |
2330 | 2309 |
| |
2331 | 2310 |
| |
2332 | 2311 |
| |
2333 | 2312 |
| |
2334 | 2313 |
| |
2335 | 2314 |
| |
| 2315 | + | |
| 2316 | + | |
| 2317 | + | |
2336 | 2318 |
| |
2337 | 2319 |
| |
2338 |
| - | |
| 2320 | + | |
2339 | 2321 |
| |
2340 | 2322 |
| |
2341 | 2323 |
| |
2342 | 2324 |
| |
2343 |
| - | |
| 2325 | + | |
| 2326 | + | |
2344 | 2327 |
| |
2345 | 2328 |
| |
2346 |
| - | |
| 2329 | + | |
| 2330 | + | |
| 2331 | + | |
| 2332 | + | |
| 2333 | + | |
| 2334 | + | |
2347 | 2335 |
| |
2348 |
| - | |
2349 |
| - | |
| 2336 | + | |
| 2337 | + | |
| 2338 | + | |
| 2339 | + | |
| 2340 | + | |
| 2341 | + | |
| 2342 | + | |
| 2343 | + | |
2350 | 2344 |
| |
2351 | 2345 |
| |
2352 | 2346 |
| |
| |||
2935 | 2929 |
| |
2936 | 2930 |
| |
2937 | 2931 |
| |
2938 |
| - | |
| 2932 | + | |
2939 | 2933 |
| |
2940 | 2934 |
| |
2941 |
| - | |
| 2935 | + | |
2942 | 2936 |
| |
2943 | 2937 |
| |
2944 | 2938 |
| |
| |||
2975 | 2969 |
| |
2976 | 2970 |
| |
2977 | 2971 |
| |
2978 |
| - | |
| 2972 | + | |
2979 | 2973 |
| |
2980 | 2974 |
| |
2981 | 2975 |
| |
| |||
2984 | 2978 |
| |
2985 | 2979 |
| |
2986 | 2980 |
| |
2987 |
| - | |
| 2981 | + | |
2988 | 2982 |
| |
2989 | 2983 |
| |
2990 | 2984 |
| |
| |||
3043 | 3037 |
| |
3044 | 3038 |
| |
3045 | 3039 |
| |
3046 |
| - | |
| 3040 | + | |
3047 | 3041 |
| |
3048 | 3042 |
| |
3049 | 3043 |
| |
3050 | 3044 |
| |
3051 | 3045 |
| |
3052 | 3046 |
| |
3053 | 3047 |
| |
3054 |
| - | |
| 3048 | + | |
3055 | 3049 |
| |
3056 | 3050 |
| |
3057 | 3051 |
| |
3058 | 3052 |
| |
3059 | 3053 |
| |
3060 |
| - | |
3061 |
| - | |
| 3054 | + | |
| 3055 | + | |
3062 | 3056 |
| |
3063 | 3057 |
| |
3064 | 3058 |
| |
3065 | 3059 |
| |
3066 | 3060 |
| |
3067 |
| - | |
3068 |
| - | |
| 3061 | + | |
| 3062 | + | |
3069 | 3063 |
| |
3070 | 3064 |
| |
3071 | 3065 |
| |
| |||
3075 | 3069 |
| |
3076 | 3070 |
| |
3077 | 3071 |
| |
3078 |
| - | |
3079 |
| - | |
| 3072 | + | |
| 3073 | + | |
3080 | 3074 |
| |
3081 | 3075 |
| |
3082 | 3076 |
| |
3083 | 3077 |
| |
3084 | 3078 |
| |
3085 | 3079 |
| |
3086 |
| - | |
3087 |
| - | |
| 3080 | + | |
| 3081 | + | |
3088 | 3082 |
| |
3089 | 3083 |
| |
3090 | 3084 |
| |
| |||
3183 | 3177 |
| |
3184 | 3178 |
| |
3185 | 3179 |
| |
3186 |
| - | |
| 3180 | + | |
3187 | 3181 |
| |
3188 | 3182 |
| |
3189 | 3183 |
| |
3190 | 3184 |
| |
3191 |
| - | |
| 3185 | + | |
3192 | 3186 |
| |
3193 | 3187 |
| |
3194 | 3188 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2808 | 2808 |
| |
2809 | 2809 |
| |
2810 | 2810 |
| |
2811 |
| - | |
| 2811 | + | |
2812 | 2812 |
| |
2813 | 2813 |
| |
2814 | 2814 |
| |
|
0 commit comments
Comments
(0)