summaryrefslogtreecommitdiff
path: root/ext/interbase
diff options
context:
space:
mode:
authorMarcus Boerger <helly@php.net>2007-02-24 02:17:47 +0000
committerMarcus Boerger <helly@php.net>2007-02-24 02:17:47 +0000
commit50ea26760da4e0fcf4980e739e1d0ed520de8d59 (patch)
tree888a32ce58864f5318a7f1072f8526c6a99212f9 /ext/interbase
parent3e262bd36989898ac01224f0a987e79f44d25b31 (diff)
downloadphp-git-50ea26760da4e0fcf4980e739e1d0ed520de8d59.tar.gz
- Avoid sprintf, even when checked copy'n'paste or changes lead to errors
Diffstat (limited to 'ext/interbase')
-rw-r--r--ext/interbase/ibase_blobs.c7
-rw-r--r--ext/interbase/ibase_query.c22
-rw-r--r--ext/interbase/ibase_service.c2
-rw-r--r--ext/interbase/interbase.c13
4 files changed, 22 insertions, 22 deletions
diff --git a/ext/interbase/ibase_blobs.c b/ext/interbase/ibase_blobs.c
index d622359c9d..4625281a11 100644
--- a/ext/interbase/ibase_blobs.c
+++ b/ext/interbase/ibase_blobs.c
@@ -74,16 +74,15 @@ int _php_ibase_string_to_quad(char const *id, ISC_QUAD *qd) /* {{{ */
char *_php_ibase_quad_to_string(ISC_QUAD const qd) /* {{{ */
{
- char *result = (char *) emalloc(BLOB_ID_LEN+1);
+ char *result;
/* shortcut for most common case */
if (sizeof(ISC_QUAD) == sizeof(ISC_UINT64)) {
- sprintf(result, "0x%0*" LL_MASK "x", 16, *(ISC_UINT64*)(void *) &qd);
+ spprintf(&result, BLOB_ID_LEN+1, "0x%0*" LL_MASK "x", 16, *(ISC_UINT64*)(void *) &qd);
} else {
ISC_UINT64 res = ((ISC_UINT64) qd.gds_quad_high << 0x20) | qd.gds_quad_low;
- sprintf(result, "0x%0*" LL_MASK "x", 16, res);
+ spprintf(&result, BLOB_ID_LEN+1, "0x%0*" LL_MASK "x", 16, res);
}
- result[BLOB_ID_LEN] = '\0';
return result;
}
/* }}} */
diff --git a/ext/interbase/ibase_query.c b/ext/interbase/ibase_query.c
index c78d0618bb..3de5879688 100644
--- a/ext/interbase/ibase_query.c
+++ b/ext/interbase/ibase_query.c
@@ -1317,17 +1317,17 @@ static int _php_ibase_var_zval(zval *val, void *data, int type, int len, /* {{{
goto _sql_long;
#else
if (scale == 0) {
- l = sprintf(string_data, "%" LL_MASK "d", *(ISC_INT64 *) data);
+ l = snprintf(string_data, sizeof(string_data), "%" LL_MASK "d", *(ISC_INT64 *) data);
ZVAL_STRINGL(val,string_data,l,1);
} else {
ISC_INT64 n = *(ISC_INT64 *) data, f = scales[-scale];
if (n >= 0) {
- l = sprintf(string_data, "%" LL_MASK "d.%0*" LL_MASK "d", n / f, -scale, n % f);
+ l = snprintf(string_data, sizeof(string_data), "%" LL_MASK "d.%0*" LL_MASK "d", n / f, -scale, n % f);
} else if (n <= -f) {
- l = sprintf(string_data, "%" LL_MASK "d.%0*" LL_MASK "d", n / f, -scale, -n % f);
+ l = snprintf(string_data, sizeof(string_data), "%" LL_MASK "d.%0*" LL_MASK "d", n / f, -scale, -n % f);
} else {
- l = sprintf(string_data, "-0.%0*" LL_MASK "d", -scale, -n % f);
+ l = snprintf(string_data, sizeof(string_data), "-0.%0*" LL_MASK "d", -scale, -n % f);
}
ZVAL_STRINGL(val,string_data,l,1);
}
@@ -1342,11 +1342,11 @@ static int _php_ibase_var_zval(zval *val, void *data, int type, int len, /* {{{
long f = (long) scales[-scale];
if (n >= 0) {
- l = sprintf(string_data, "%ld.%0*ld", n / f, -scale, n % f);
+ l = snprintf(string_data, sizeof(string_data), "%ld.%0*ld", n / f, -scale, n % f);
} else if (n <= -f) {
- l = sprintf(string_data, "%ld.%0*ld", n / f, -scale, -n % f);
+ l = snprintf(string_data, sizeof(string_data), "%ld.%0*ld", n / f, -scale, -n % f);
} else {
- l = sprintf(string_data, "-0.%0*ld", -scale, -n % f);
+ l = snprintf(string_data, sizeof(string_data), "-0.%0*ld", -scale, -n % f);
}
ZVAL_STRINGL(val,string_data,l,1);
}
@@ -1386,14 +1386,14 @@ format_date_time:
#else
switch (type & ~1) {
default:
- l = sprintf(string_data, "%02d/%02d/%4d %02d:%02d:%02d", t.tm_mon+1, t.tm_mday,
+ l = snprintf(string_data, sizeof(string_data), "%02d/%02d/%4d %02d:%02d:%02d", t.tm_mon+1, t.tm_mday,
t.tm_year + 1900, t.tm_hour, t.tm_min, t.tm_sec);
break;
case SQL_TYPE_DATE:
- l = sprintf(string_data, "%02d/%02d/%4d", t.tm_mon + 1, t.tm_mday, t.tm_year+1900);
+ l = snprintf(string_data, sizeof(string_data), "%02d/%02d/%4d", t.tm_mon + 1, t.tm_mday, t.tm_year+1900);
break;
case SQL_TYPE_TIME:
- l = sprintf(string_data, "%02d:%02d:%02d", t.tm_hour, t.tm_min, t.tm_sec);
+ l = snprintf(string_data, sizeof(string_data), "%02d:%02d:%02d", t.tm_hour, t.tm_min, t.tm_sec);
break;
}
#endif
@@ -1525,7 +1525,7 @@ static void _php_ibase_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int fetch_type)
Z_ARRVAL_P(return_value),alias,strlen(alias)+1,&p)) {
case '\0':
- sprintf(alias = buf, "%s_%02d", base, i++);
+ snprintf(alias = buf, sizeof(buf), "%s_%02d", base, i++);
}
}
}
diff --git a/ext/interbase/ibase_service.c b/ext/interbase/ibase_service.c
index 4d610aa6ee..4ddb74e0d6 100644
--- a/ext/interbase/ibase_service.c
+++ b/ext/interbase/ibase_service.c
@@ -322,7 +322,7 @@ query_loop:
heap_p = heap_buf + res_size;
}
result += 2;
- sprintf(heap_p, "%s\n", result);
+ snprintf(heap_p, sizeof(heap_buf_size), "%s\n", result);
heap_p += line_len +2;
goto query_loop; /* repeat until result is exhausted */
diff --git a/ext/interbase/interbase.c b/ext/interbase/interbase.c
index 63d09e0eb3..a040cc6845 100644
--- a/ext/interbase/interbase.c
+++ b/ext/interbase/interbase.c
@@ -542,7 +542,7 @@ PHP_MINFO_FUNCTION(ibase)
#endif
#ifdef FB_API_VER
- sprintf( (s = tmp), "Firebird API version %d", FB_API_VER);
+ snprintf( (s = tmp), sizeof(tmp), "Firebird API version %d", FB_API_VER);
#elif (SQLDA_CURRENT_VERSION > 1)
s = "Interbase 7.0 and up";
#elif !defined(DSC_null)
@@ -607,7 +607,7 @@ int _php_ibase_attach_db(char **args, int *len, long *largs, isc_db_handle *db T
buf_len -= dpb_len;
}
if (largs[SYNC] && buf_len > 0) {
- dpb_len = sprintf(dpb, buf_len, "%c\1%c", isc_dpb_force_write, largs[SYNC] == isc_spb_prp_wm_sync ? 1 : 0);
+ dpb_len = snprintf(dpb, buf_len, "%c\1%c", isc_dpb_force_write, largs[SYNC] == isc_spb_prp_wm_sync ? 1 : 0);
dpb += dpb_len;
buf_len -= dpb_len;
}
@@ -1170,7 +1170,7 @@ PHP_FUNCTION(ibase_gen_id)
PHP_IBASE_LINK_TRANS(link, ib_link, trans);
- sprintf(query, "SELECT GEN_ID(%s,%ld) FROM rdb$database", generator, inc);
+ snprintf(query, sizeof(query), "SELECT GEN_ID(%s,%ld) FROM rdb$database", generator, inc);
/* allocate a minimal descriptor area */
out_sqlda.sqln = out_sqlda.sqld = 1;
@@ -1192,10 +1192,11 @@ PHP_FUNCTION(ibase_gen_id)
/* don't return the generator value as a string unless it doesn't fit in a long */
#if SIZEOF_LONG < 8
if (result < LONG_MIN || result > LONG_MAX) {
- char res[24];
+ char *res;
+ int l
- sprintf(res, "%" LL_MASK "d", result);
- RETURN_STRING(res,1);
+ l = spprintf(&res, 0, "%" LL_MASK "d", result);
+ RETURN_STRINGL(res, l, 0);
}
#endif
RETURN_LONG((long)result);