@@ -274,38 +274,38 @@ static int firebird_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int unqu
274
274
char * * quoted , int * quotedlen , enum pdo_param_type paramtype TSRMLS_DC )
275
275
{
276
276
int qcount = 0 ;
277
- char const * c ;
277
+ char const * co , * l , * r ;
278
+ char * c ;
278
279
280
+ if (!unquotedlen ) {
281
+ * quotedlen = 2 ;
282
+ * quoted = emalloc (* quotedlen + 1 );
283
+ strcpy (* quoted , "''" );
284
+ return 1 ;
285
+ }
286
+
279
287
/* Firebird only requires single quotes to be doubled if string lengths are used */
280
-
281
288
/* count the number of ' characters */
282
- for (c = unquoted ; (c = strchr (c ,'\'' )); qcount ++ , c ++ );
289
+ for (co = unquoted ; (co = strchr (co ,'\'' )); qcount ++ , co ++ );
283
290
284
- if (!qcount ) {
285
- return 0 ;
286
- } else {
287
- char const * l , * r ;
288
- char * c ;
289
-
290
- * quotedlen = unquotedlen + qcount ;
291
- * quoted = c = emalloc (* quotedlen + 1 );
292
-
293
- /* foreach (chunk that ends in a quote) */
294
- for (l = unquoted ; (r = strchr (l ,'\'' )); l = r + 1 ) {
295
-
296
- /* copy the chunk */
297
- strncpy (c , l , r - l );
298
- c += (r - l );
299
-
300
- /* add the second quote */
301
- * c ++ = '\'' ;
302
- }
303
-
304
- /* copy the remainder */
305
- strncpy (c , l , * quotedlen - (c - * quoted ));
291
+ * quotedlen = unquotedlen + qcount + 2 ;
292
+ * quoted = c = emalloc (* quotedlen + 1 );
293
+ * c ++ = '\'' ;
294
+
295
+ /* foreach (chunk that ends in a quote) */
296
+ for (l = unquoted ; (r = strchr (l ,'\'' )); l = r + 1 ) {
297
+ strncpy (c , l , r - l + 1 );
298
+ c += (r - l + 1 );
299
+ /* add the second quote */
300
+ * c ++ = '\'' ;
301
+ }
306
302
307
- return 1 ;
308
- }
303
+ /* copy the remainder */
304
+ strncpy (c , l , * quotedlen - (c - * quoted )- 1 );
305
+ (* quoted )[* quotedlen - 1 ] = '\'' ;
306
+ (* quoted )[* quotedlen ] = '\0' ;
307
+
308
+ return 1 ;
309
309
}
310
310
/* }}} */
311
311
0 commit comments