From 3596f77222c1c24cc20ce7f9ac4b3a604cfca39c Mon Sep 17 00:00:00 2001 From: miker Date: Sun, 30 Sep 2007 18:47:04 +0000 Subject: [PATCH] Patch from Dan Scott to remove bzero in favor of memset (which may also go away) and use sizeof instead of static lengths in memset and snprintf. git-svn-id: svn://svn.open-ils.org/ILS/trunk@7852 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/apachemods/mod_rest_gateway.c | 4 ++-- Open-ILS/src/apachemods/mod_xmlbuilder.c | 8 ++++---- Open-ILS/src/apachemods/mod_xmlent.c | 2 +- Open-ILS/src/c-apps/oils_cstore.c | 4 ++-- Open-ILS/src/c-apps/oils_event.c | 4 ++-- Open-ILS/src/c-apps/oils_fetch.c | 9 +++------ Open-ILS/src/c-apps/oils_utils.c | 3 +-- 7 files changed, 15 insertions(+), 19 deletions(-) diff --git a/Open-ILS/src/apachemods/mod_rest_gateway.c b/Open-ILS/src/apachemods/mod_rest_gateway.c index 2c93229c47..0ab87c55b6 100644 --- a/Open-ILS/src/apachemods/mod_rest_gateway.c +++ b/Open-ILS/src/apachemods/mod_rest_gateway.c @@ -85,12 +85,12 @@ static int mod_ils_gateway_method_handler (request_rec *r) { } char body[1025]; - memset(body,0,1025); + memset(body, '\0', sizeof(body)); buffer = buffer_init(1025); while(ap_get_client_block(r, body, 1024)) { buffer_add( buffer, body ); - memset(body,0,1025); + memset(body, '\0', sizeof(body)); } if(arg && arg[0]) { diff --git a/Open-ILS/src/apachemods/mod_xmlbuilder.c b/Open-ILS/src/apachemods/mod_xmlbuilder.c index c760de2e9c..7c316ff39b 100644 --- a/Open-ILS/src/apachemods/mod_xmlbuilder.c +++ b/Open-ILS/src/apachemods/mod_xmlbuilder.c @@ -245,7 +245,7 @@ void xmlBuilderStartElement( void* context, const xmlChar *name, const xmlChar * if(href[0] != '/') { int len = strlen(ctx->xmlFile) + strlen(href) + 1; char buf[len]; - bzero(buf, len); + memset( buf, '\0', sizeof(len) ); strcpy( buf, ctx->xmlFile ); int i; for( i = strlen(buf); i != 0; i-- ) { @@ -300,7 +300,7 @@ void xmlBuilderAddAtts( xmlBuilderContext* ctx, xmlNodePtr node, const xmlChar** if( prop[0] == '&' && prop[nl-1] == ';' ) { /* replace the entity if we are one */ char buf[nl+1]; - bzero(buf, nl+1); + memset( buf, '\0', sizeof(buf) ); strncat(buf, prop + 1, nl - 2); xmlEntityPtr ent = osrfHashGet( ctx->entHash, buf ); if(ent && ent->content) _prop = ent->content; @@ -392,8 +392,8 @@ void xmlBuilderAddDtd( const char* sysId, xmlBuilderContext* context ) { /* determine the path to the DTD file and load it */ int len = strlen(context->config->baseDir) + strlen(locale) + strlen(sysId) + 4; - char buf[len]; bzero(buf,len); - snprintf( buf, len, "%s/%s/%s", context->config->baseDir, locale, sysId ); + char buf[len]; + snprintf( buf, sizeof(buf), "%s/%s/%s", context->config->baseDir, locale, sysId ); xmlDtdPtr dtd = xmlParseDTD(NULL, buf); if(!dtd) return; diff --git a/Open-ILS/src/apachemods/mod_xmlent.c b/Open-ILS/src/apachemods/mod_xmlent.c index 2df9eb61c7..757dd794bb 100644 --- a/Open-ILS/src/apachemods/mod_xmlent.c +++ b/Open-ILS/src/apachemods/mod_xmlent.c @@ -202,7 +202,7 @@ static void XMLCALL startElement(void *userData, const char *name, const char ** static void XMLCALL charHandler( void* userData, const XML_Char* s, int len ) { ap_filter_t* filter = (ap_filter_t*) userData; char data[len+1]; - bzero(data, len+1); + memset( data, '\0', sizeof(data) ); memcpy( data, s, len ); xmlEntConfig* config = ap_get_module_config( diff --git a/Open-ILS/src/c-apps/oils_cstore.c b/Open-ILS/src/c-apps/oils_cstore.c index 10225c064f..b44c57ee98 100644 --- a/Open-ILS/src/c-apps/oils_cstore.c +++ b/Open-ILS/src/c-apps/oils_cstore.c @@ -2970,7 +2970,7 @@ jsonObject* oilsMakeFieldmapperFromResult( dbi_result result, osrfHash* meta) { case DBI_TYPE_DATETIME : - memset(dt_string, '\0', 256); + memset(dt_string, '\0', sizeof(dt_string)); memset(&gmdt, '\0', sizeof(gmdt)); memset(&_tmp_dt, '\0', sizeof(_tmp_dt)); @@ -3049,7 +3049,7 @@ jsonObject* oilsMakeJSONFromResult( dbi_result result ) { case DBI_TYPE_DATETIME : - memset(dt_string, '\0', 256); + memset(dt_string, '\0', sizeof(dt_string)); memset(&gmdt, '\0', sizeof(gmdt)); memset(&_tmp_dt, '\0', sizeof(_tmp_dt)); diff --git a/Open-ILS/src/c-apps/oils_event.c b/Open-ILS/src/c-apps/oils_event.c index f0585cee87..dfb8936e73 100644 --- a/Open-ILS/src/c-apps/oils_event.c +++ b/Open-ILS/src/c-apps/oils_event.c @@ -86,8 +86,8 @@ jsonObject* oilsEventToJSON( oilsEvent* event ) { jsonObjectSetKey( json, "pid", jsonNewNumberObject(getpid()) ); char buf[256]; - memset(buf,0, 256); - snprintf(buf, 256, "%s:%d", event->file, event->line); + memset(buf, '\0', sizeof(buf)); + snprintf(buf, sizeof(buf), "%s:%d", event->file, event->line); jsonObjectSetKey( json, "stacktrace", jsonNewObject(buf) ); if(event->perm) jsonObjectSetKey( json, "ilsperm", jsonNewObject(event->perm) ); diff --git a/Open-ILS/src/c-apps/oils_fetch.c b/Open-ILS/src/c-apps/oils_fetch.c index 34ce92f045..559ebb8435 100644 --- a/Open-ILS/src/c-apps/oils_fetch.c +++ b/Open-ILS/src/c-apps/oils_fetch.c @@ -50,8 +50,7 @@ int osrfAppInitialize() { osrfHashSet( fmClassMap, hint, apiname ); char method[256]; - bzero(method, 256); - snprintf(method, 256, "open-ils.fetch.%s.retrieve", apiname); + snprintf(method, sizeof(method), "open-ils.fetch.%s.retrieve", apiname); osrfAppRegisterMethod( MODULENAME, method, "oilsFetchDoRetrieve", "", 1, 0 ); @@ -129,13 +128,11 @@ int oilsFetchDoRetrieve( osrfMethodContext* ctx ) { /* construct the SQL */ char sql[256]; - bzero(sql, 256); - snprintf( sql, 255, "select * from %s.%s where id = %s;", schema, object, id ); + snprintf( sql, sizeof(sql), "select * from %s.%s where id = %s;", schema, object, id ); /* find the object hint from the api name */ char hintbuf[256]; - bzero(hintbuf,256); - snprintf(hintbuf, 255, "%s.%s", schema, object ); + snprintf(hintbuf, sizeof(hintbuf), "%s.%s", schema, object ); char* hint = osrfHashGet( fmClassMap, hintbuf ); osrfLogDebug(OSRF_LOG_MARK, "%s SQL = %s", MODULENAME, sql); diff --git a/Open-ILS/src/c-apps/oils_utils.c b/Open-ILS/src/c-apps/oils_utils.c index a572316b27..168fc1b022 100644 --- a/Open-ILS/src/c-apps/oils_utils.c +++ b/Open-ILS/src/c-apps/oils_utils.c @@ -189,8 +189,7 @@ char* oilsUtilsLogin( char* uname, char* passwd, char* type, int orgId ) { char* seed = jsonObjectGetString(o); char* passhash = md5sum(passwd); char buf[256]; - bzero(buf, 256); - snprintf(buf, 255, "%s%s", seed, passhash); + snprintf(buf, sizeof(buf), "%s%s", seed, passhash); char* fullhash = md5sum(buf); jsonObjectFree(o); -- 2.43.2