[Opensrf-commits] r1098 - in trunk/src: gateway jserver libopensrf
objson router srfsh
svn at svn.open-ils.org
svn at svn.open-ils.org
Sun Sep 30 15:24:50 EDT 2007
Author: miker
Date: 2007-09-30 15:14:26 -0400 (Sun, 30 Sep 2007)
New Revision: 1098
Modified:
trunk/src/gateway/apachetools.c
trunk/src/gateway/osrf_json_gateway.c
trunk/src/jserver/osrf_chat.c
trunk/src/libopensrf/basic_client.c
trunk/src/libopensrf/log.c
trunk/src/libopensrf/osrf_app_session.c
trunk/src/libopensrf/osrf_json_parser.c
trunk/src/libopensrf/osrf_json_test.c
trunk/src/libopensrf/osrf_legacy_json.c
trunk/src/libopensrf/osrf_message.c
trunk/src/libopensrf/osrf_prefork.c
trunk/src/libopensrf/osrf_stack.c
trunk/src/libopensrf/osrf_transgroup.c
trunk/src/libopensrf/socket_bundle.c
trunk/src/libopensrf/transport_session.c
trunk/src/libopensrf/utils.c
trunk/src/objson/json_parser.c
trunk/src/objson/objson_test.c
trunk/src/router/osrf_router.c
trunk/src/srfsh/srfsh.c
Log:
Broad patch from Dan Scott to move towards better memory management:
* bzero->memset (with sizeof) - except when followed immediately by
snprintf(), in which case the call was deleted completely
* sprintf->snprintf (with sizeof) - for the C99-guaranteed
null-terminated string and avoidance of overwrites
* fgets (with sizeof) - because in at least one case "len - 1" was
being used for the length, even though fgets is defined to retrieve 1
byte less than the requested length - so the code was effectively
retrieving 2 bytes less than the allocated buffer
* in 2 places in srfsh.c, increased buffer size by 1 to allow for
null terminator
* various typo fixes
Modified: trunk/src/gateway/apachetools.c
===================================================================
--- trunk/src/gateway/apachetools.c 2007-09-30 18:53:17 UTC (rev 1097)
+++ trunk/src/gateway/apachetools.c 2007-09-30 19:14:26 UTC (rev 1098)
@@ -24,7 +24,7 @@
if(ap_should_client_block(r)) {
char body[1025];
- memset(body,0,1025);
+ memset(body,0,sizeof(body));
buffer = buffer_init(1025);
@@ -40,7 +40,7 @@
}
buffer_add( buffer, body );
- memset(body,0,1025);
+ memset(body,0,sizeof(body));
osrfLogDebug(OSRF_LOG_MARK,
"gateway read %d bytes: %d bytes of data so far", bread, buffer->n_used);
@@ -49,7 +49,7 @@
if(buffer->n_used > APACHE_TOOLS_MAX_POST_SIZE) {
osrfLogError(OSRF_LOG_MARK, "gateway received POST larger "
- "than %d bytes. dropping reqeust", APACHE_TOOLS_MAX_POST_SIZE);
+ "than %d bytes. dropping request", APACHE_TOOLS_MAX_POST_SIZE);
buffer_free(buffer);
return NULL;
}
Modified: trunk/src/gateway/osrf_json_gateway.c
===================================================================
--- trunk/src/gateway/osrf_json_gateway.c 2007-09-30 18:53:17 UTC (rev 1097)
+++ trunk/src/gateway/osrf_json_gateway.c 2007-09-30 19:14:26 UTC (rev 1098)
@@ -90,9 +90,8 @@
char* cfg = osrf_json_gateway_config_file;
char buf[32];
- memset(buf, 0x0, 32);
int t = time(NULL);
- snprintf(buf, 32, "%d", t);
+ snprintf(buf, sizeof(buf), "%d", t);
if( ! osrfSystemBootstrapClientResc( cfg, CONFIG_CONTEXT, buf ) ) {
ap_log_error( APLOG_MARK, APLOG_ERR, 0, s,
@@ -377,18 +376,16 @@
"OpenSRF JSON Request returned error: %s -> %s", statusname, statustext );
int l = strlen(statusname) + strlen(statustext) + 32;
char buf[l];
- bzero(buf,l);
if (isXML)
- snprintf( buf, l, "<debug>\"%s : %s\"</debug>", statusname, statustext );
+ snprintf( buf, sizeof(buf), "<debug>\"%s : %s\"</debug>", statusname, statustext );
else {
char bb[l];
- bzero(bb, l);
- snprintf(bb, l, "%s : %s", statusname, statustext);
+ snprintf(bb, sizeof(bb), "%s : %s", statusname, statustext);
jsonObject* tmp = jsonNewObject(bb);
char* j = jsonToStringFunc(tmp);
- snprintf( buf, l, ",\"debug\": %s", j);
+ snprintf( buf, sizeof(buf), ",\"debug\": %s", j);
free(j);
jsonObjectFree(tmp);
}
@@ -401,12 +398,11 @@
/* insert the status code */
char buf[32];
- bzero(buf,32);
if (isXML)
- snprintf(buf, 32, "<status>%d</status>", statuscode );
+ snprintf(buf, sizeof(buf), "<status>%d</status>", statuscode );
else
- snprintf(buf, 32, ",\"status\":%d", statuscode );
+ snprintf(buf, sizeof(buf), ",\"status\":%d", statuscode );
ap_rputs( buf, r );
Modified: trunk/src/jserver/osrf_chat.c
===================================================================
--- trunk/src/jserver/osrf_chat.c 2007-09-30 18:53:17 UTC (rev 1097)
+++ trunk/src/jserver/osrf_chat.c 2007-09-30 19:14:26 UTC (rev 1098)
@@ -279,7 +279,7 @@
int l = strlen(toAddr);
char dombuf[l];
- bzero(dombuf, l);
+ memset(dombuf, 0, sizeof(dombuf));
jid_get_domain( toAddr, dombuf, l );
if( eq( dombuf, cs->domain ) ) { /* this is to a user we host */
@@ -595,8 +595,7 @@
char* osrfChatMkAuthKey() {
char keybuf[112];
- bzero(keybuf, 112);
- snprintf(keybuf, 111, "%d%ld%s", (int) time(NULL), (long) getpid(), getenv("HOSTNAME"));
+ snprintf(keybuf, sizeof(keybuf), "%d%ld%s", (int) time(NULL), (long) getpid(), getenv("HOSTNAME"));
return strdup(shahash(keybuf));
}
Modified: trunk/src/libopensrf/basic_client.c
===================================================================
--- trunk/src/libopensrf/basic_client.c 2007-09-30 18:53:17 UTC (rev 1097)
+++ trunk/src/libopensrf/basic_client.c 2007-09-30 19:14:26 UTC (rev 1098)
@@ -31,10 +31,10 @@
signal(SIGINT, sig_int);
fprintf(stderr, "Listener: %ld\n", (long) getpid() );
char buf[300];
- memset(buf, 0, 300);
+ memset(buf, 0, sizeof(buf));
printf("=> ");
- while( fgets( buf, 299, stdin) ) {
+ while( fgets( buf, sizeof(buf), stdin) ) {
// remove newline
buf[strlen(buf)-1] = '\0';
@@ -48,7 +48,7 @@
client_send_message( client, send );
message_free( send );
printf("\n=> ");
- memset(buf, 0, 300);
+ memset(buf, 0, sizeof(buf));
}
fprintf(stderr, "Killing child %d\n", pid );
kill( pid, SIGKILL );
Modified: trunk/src/libopensrf/log.c
===================================================================
--- trunk/src/libopensrf/log.c 2007-09-30 18:53:17 UTC (rev 1097)
+++ trunk/src/libopensrf/log.c 2007-09-30 19:14:26 UTC (rev 1098)
@@ -58,8 +58,7 @@
if(_osrfLogIsClient) {
static int _osrfLogXidInc = 0; /* increments with each new xid for uniqueness */
char buf[32];
- memset(buf, 0x0, 32);
- snprintf(buf, 32, "%s%d", _osrfLogXidPfx, _osrfLogXidInc);
+ snprintf(buf, sizeof(buf), "%s%d", _osrfLogXidPfx, _osrfLogXidInc);
_osrfLogSetXid(buf);
_osrfLogXidInc++;
}
@@ -74,8 +73,7 @@
if(!is) return;
/* go ahead and create the xid prefix so it will be consistent later */
static char buff[32];
- memset(buff, 0x0, 32);
- snprintf(buff, 32, "%d%ld", (int)time(NULL), (long) getpid());
+ snprintf(buff, sizeof(buff), "%d%ld", (int)time(NULL), (long) getpid());
_osrfLogXidPfx = buff;
}
@@ -223,7 +221,7 @@
if( logtype == OSRF_LOG_TYPE_SYSLOG ) {
char buf[1536];
- memset(buf, 0x0, 1536);
+ memset(buf, 0x0, sizeof(buf));
/* give syslog some breathing room, and be cute about it */
strncat(buf, msg, 1535);
buf[1532] = '.';
Modified: trunk/src/libopensrf/osrf_app_session.c
===================================================================
--- trunk/src/libopensrf/osrf_app_session.c 2007-09-30 18:53:17 UTC (rev 1097)
+++ trunk/src/libopensrf/osrf_app_session.c 2007-09-30 19:14:26 UTC (rev 1098)
@@ -240,7 +240,7 @@
char target_buf[512];
target_buf[ 0 ] = '\0';
- int len = snprintf( target_buf, 512, "%s@%s/%s",
+ int len = snprintf( target_buf, sizeof(target_buf), "%s@%s/%s",
router_name ? router_name : "(null)",
domain ? domain : "(null)",
remote_service ? remote_service : "(null)" );
@@ -271,9 +271,8 @@
/* build a chunky, random session id */
char id[256];
- memset(id,0,256);
- sprintf(id, "%f.%d%ld", get_timestamp_millis(), (int)time(NULL), (long) getpid());
+ snprintf(id, sizeof(id), "%f.%d%ld", get_timestamp_millis(), (int)time(NULL), (long) getpid());
session->session_id = strdup(id);
osrfLogDebug( OSRF_LOG_MARK, "Building a new client session with id [%s] [%s]",
session->remote_service, session->session_id );
Modified: trunk/src/libopensrf/osrf_json_parser.c
===================================================================
--- trunk/src/libopensrf/osrf_json_parser.c 2007-09-30 18:53:17 UTC (rev 1097)
+++ trunk/src/libopensrf/osrf_json_parser.c 2007-09-30 19:14:26 UTC (rev 1098)
@@ -75,8 +75,7 @@
while( post >= ctx->chunksize ) post--;
int l = post - pre;
char buf[l];
- memset(buf, 0, l);
- snprintf(buf, l, ctx->chunk + pre);
+ snprintf(buf, sizeof(buf), ctx->chunk + pre);
ctx->handler->handleError( ctx->userData,
"*JSON Parser Error\n - char = %c\n "
"- index = %d\n - near => %s\n - %s",
@@ -107,7 +106,7 @@
*/
#define hexdigit(x) ( ((x) <= '9') ? (x) - '0' : ((x) & 7) + 9)
unsigned char utf_out[4];
- memset(utf_out,0,4);
+ memset(utf_out, 0, sizeof(utf_out));
char* buf = ctx->utfbuf->buf;
unsigned int ucs_char =
Modified: trunk/src/libopensrf/osrf_json_test.c
===================================================================
--- trunk/src/libopensrf/osrf_json_test.c 2007-09-30 18:53:17 UTC (rev 1097)
+++ trunk/src/libopensrf/osrf_json_test.c 2007-09-30 19:14:26 UTC (rev 1098)
@@ -32,8 +32,7 @@
for(i = 0; i < count; i++) {
- memset(buf, 0, 16);
- snprintf(buf, 16, "key_%d", i);
+ snprintf(buf, sizeof(buf), "key_%d", i);
array = jsonNewObject(NULL);
for(k = 0; k < count + i; k++) {
Modified: trunk/src/libopensrf/osrf_legacy_json.c
===================================================================
--- trunk/src/libopensrf/osrf_legacy_json.c 2007-09-30 18:53:17 UTC (rev 1097)
+++ trunk/src/libopensrf/osrf_legacy_json.c 2007-09-30 19:14:26 UTC (rev 1098)
@@ -94,12 +94,13 @@
/* json string */
case '"':
(*index)++;
- status = json_parse_json_string(string, index, obj, current_strlen); break;
+ status = json_parse_json_string(string, index, obj, current_strlen);
+ break;
/* json array */
case '[':
(*index)++;
- status = json_parse_json_array(string, index, obj, current_strlen);
+ status = json_parse_json_array(string, index, obj, current_strlen);
break;
/* json object */
@@ -125,7 +126,7 @@
default:
if(isdigit(c) || c == '.' || c == '-') { /* are we a number? */
- status = json_parse_json_number(string, index, obj, current_strlen);
+ status = json_parse_json_number(string, index, obj, current_strlen);
if(status) return status;
break;
}
@@ -479,7 +480,7 @@
"json_parse_json_string(): truncated escaped unicode"); }
char buff[5];
- memset(buff,0,5);
+ memset(buff, 0, sizeof(buff));
memcpy(buff, string + (*index), 4);
@@ -488,7 +489,7 @@
/* The following chunk was borrowed with permission from
json-c http://oss.metaparadigm.com/json-c/ */
unsigned char utf_out[3];
- memset(utf_out,0,3);
+ memset(utf_out, 0, sizeof(utf_out));
#define hexdigit(x) ( ((x) <= '9') ? (x) - '0' : ((x) & 7) + 9)
@@ -692,7 +693,7 @@
int json_handle_error(char* string, unsigned long* index, char* err_msg) {
char buf[60];
- memset(buf, 0, 60);
+ memset(buf, 0, sizeof(buf));
if(*index > 30)
strncpy( buf, string + (*index - 30), 59 );
Modified: trunk/src/libopensrf/osrf_message.c
===================================================================
--- trunk/src/libopensrf/osrf_message.c 2007-09-30 18:53:17 UTC (rev 1097)
+++ trunk/src/libopensrf/osrf_message.c 2007-09-30 19:14:26 UTC (rev 1098)
@@ -174,7 +174,8 @@
jsonObject* json = jsonNewObject(NULL);
jsonObjectSetClass(json, "osrfMessage");
jsonObject* payload;
- char sc[64]; memset(sc,0,64);
+ char sc[64];
+ memset(sc, 0, sizeof(sc));
char* str;
@@ -204,7 +205,7 @@
payload = jsonNewObject(NULL);
jsonObjectSetClass(payload, msg->status_name);
jsonObjectSetKey(payload, "status", jsonNewObject(msg->status_text));
- sprintf(sc,"%d",msg->status_code);
+ snprintf(sc, sizeof(sc), "%d", msg->status_code);
jsonObjectSetKey(payload, "statusCode", jsonNewObject(sc));
jsonObjectSetKey(json, "payload", payload);
break;
@@ -226,7 +227,7 @@
payload = jsonNewObject(NULL);
jsonObjectSetClass(payload,"osrfResult");
jsonObjectSetKey(payload, "status", jsonNewObject(msg->status_text));
- sprintf(sc,"%d",msg->status_code);
+ snprintf(sc, sizeof(sc), "%d", msg->status_code);
jsonObjectSetKey(payload, "statusCode", jsonNewObject(sc));
str = jsonObjectToJSON(msg->_result_content);
jsonObjectSetKey(payload, "content", jsonParseString(str));
Modified: trunk/src/libopensrf/osrf_prefork.c
===================================================================
--- trunk/src/libopensrf/osrf_prefork.c 2007-09-30 18:53:17 UTC (rev 1097)
+++ trunk/src/libopensrf/osrf_prefork.c 2007-09-30 19:14:26 UTC (rev 1098)
@@ -210,7 +210,7 @@
/* if no data was reveived within the timeout interval */
if( !recvd && (end - start) >= keepalive ) {
- osrfLogInfo(OSRF_LOG_MARK, "No request was reveived in %d seconds, exiting stateful session", keepalive);
+ osrfLogInfo(OSRF_LOG_MARK, "No request was received in %d seconds, exiting stateful session", keepalive);
osrfAppSessionStatus(
session,
OSRF_STATUS_TIMEOUT,
@@ -547,9 +547,9 @@
/* now suck off the data */
char buf[64];
- memset( buf, 0, 64);
+ memset( buf, 0, sizeof(buf) );
if( (n=read(cur_child->read_status_fd, buf, 63)) < 0 ) {
- osrfLogWarning( OSRF_LOG_MARK, "Read error afer select in child status read with errno %d", errno);
+ osrfLogWarning( OSRF_LOG_MARK, "Read error after select in child status read with errno %d", errno);
}
osrfLogDebug( OSRF_LOG_MARK, "Read %d bytes from status buffer: %s", n, buf );
@@ -566,7 +566,7 @@
int i,n;
growing_buffer* gbuf = buffer_init( READ_BUFSIZE );
char buf[READ_BUFSIZE];
- memset( buf, 0, READ_BUFSIZE );
+ memset( buf, 0, sizeof(buf) );
for( i = 0; i < child->max_requests; i++ ) {
@@ -579,7 +579,7 @@
if(!gotdata)
set_fl(child->read_data_fd, O_NONBLOCK );
buffer_add( gbuf, buf );
- memset( buf, 0, READ_BUFSIZE );
+ memset( buf, 0, sizeof(buf) );
gotdata = 1;
}
Modified: trunk/src/libopensrf/osrf_stack.c
===================================================================
--- trunk/src/libopensrf/osrf_stack.c 2007-09-30 18:53:17 UTC (rev 1097)
+++ trunk/src/libopensrf/osrf_stack.c 2007-09-30 19:14:26 UTC (rev 1098)
@@ -67,7 +67,7 @@
osrf_app_session_set_remote( session, msg->sender );
osrf_message* arr[OSRF_MAX_MSGS_PER_PACKET];
- memset(arr, 0, OSRF_MAX_MSGS_PER_PACKET );
+ memset(arr, 0, sizeof(arr));
int num_msgs = osrf_message_deserialize(msg->body, arr, OSRF_MAX_MSGS_PER_PACKET);
osrfLogDebug( OSRF_LOG_MARK, "We received %d messages from %s", num_msgs, msg->sender );
@@ -92,7 +92,7 @@
} else {
osrfLogWarning( OSRF_LOG_MARK, " * Jabber Error is for top level remote id [%s], no one "
- "to send my message too!!!", session->remote_id );
+ "to send my message to!!!", session->remote_id );
}
}
Modified: trunk/src/libopensrf/osrf_transgroup.c
===================================================================
--- trunk/src/libopensrf/osrf_transgroup.c 2007-09-30 18:53:17 UTC (rev 1097)
+++ trunk/src/libopensrf/osrf_transgroup.c 2007-09-30 19:14:26 UTC (rev 1098)
@@ -89,7 +89,7 @@
if(!(grp && msg)) return -1;
char domain[256];
- bzero(domain, 256);
+ memset(domain, 0, sizeof(domain));
jid_get_domain( msg->recipient, domain, 255 );
osrfTransportGroupNode* node = osrfHashGet(grp->nodes, domain);
@@ -108,15 +108,15 @@
int bufsize = 256;
char domain[bufsize];
- bzero(domain, bufsize);
+ memset(domain, 0, sizeof(domain));
jid_get_domain( msg->recipient, domain, bufsize - 1 );
char msgrecip[bufsize];
- bzero(msgrecip, bufsize);
+ memset(msgrecip, 0, sizeof(msgrecip));
jid_get_username(msg->recipient, msgrecip, bufsize - 1);
char msgres[bufsize];
- bzero(msgres, bufsize);
+ memset(msgres, 0, sizeof(msgres));
jid_get_resource(msg->recipient, msgres, bufsize - 1);
char* firstdomain = NULL;
@@ -149,8 +149,7 @@
/* update the recipient domain if necessary */
if(updateRecip) {
- bzero(newrcp, 1024);
- sprintf(newrcp, "%s@%s/%s", msgrecip, node->domain, msgres);
+ snprintf(newrcp, sizeof(newrcp), "%s@%s/%s", msgrecip, node->domain, msgres);
free(msg->recipient);
msg->recipient = strdup(newrcp);
}
Modified: trunk/src/libopensrf/socket_bundle.c
===================================================================
--- trunk/src/libopensrf/socket_bundle.c 2007-09-30 18:53:17 UTC (rev 1097)
+++ trunk/src/libopensrf/socket_bundle.c 2007-09-30 19:14:26 UTC (rev 1098)
@@ -707,7 +707,7 @@
int read_bytes;
int sock_fd = node->sock_fd;
- memset(buf, 0, RBUFSIZE);
+ memset(buf, 0, sizeof(buf));
set_fl(sock_fd, O_NONBLOCK);
osrfLogInternal( OSRF_LOG_MARK, "%ld : Received data at %f\n", (long) getpid(), get_timestamp_millis());
@@ -717,7 +717,7 @@
if(mgr->data_received)
mgr->data_received(mgr->blob, mgr, sock_fd, buf, node->parent_id);
- memset(buf, 0, RBUFSIZE);
+ memset(buf, 0, sizeof(buf));
}
int local_errno = errno; /* capture errno as set by recv() */
Modified: trunk/src/libopensrf/transport_session.c
===================================================================
--- trunk/src/libopensrf/transport_session.c 2007-09-30 18:53:17 UTC (rev 1097)
+++ trunk/src/libopensrf/transport_session.c 2007-09-30 19:14:26 UTC (rev 1098)
@@ -183,8 +183,7 @@
char* our_hostname = getenv("HOSTNAME");
size1 = 150 + strlen( server );
char stanza1[ size1 ];
- memset( stanza1, 0, size1 );
- sprintf( stanza1,
+ snprintf( stanza1, sizeof(stanza1),
"<stream:stream version='1.0' xmlns:stream='http://etherx.jabber.org/streams' "
"xmlns='jabber:component:accept' to='%s' from='%s' xml:lang='en'>",
username, our_hostname );
@@ -207,14 +206,12 @@
int ss = session->session_id->n_used + strlen(password) + 5;
char hashstuff[ss];
- memset(hashstuff,0,ss);
- sprintf( hashstuff, "%s%s", session->session_id->buf, password );
+ snprintf( hashstuff, sizeof(hashstuff), "%s%s", session->session_id->buf, password );
char* hash = shahash( hashstuff );
size2 = 100 + strlen( hash );
char stanza2[ size2 ];
- memset( stanza2, 0, size2 );
- sprintf( stanza2, "<handshake>%s</handshake>", hash );
+ snprintf( stanza2, sizeof(stanza2), "<handshake>%s</handshake>", hash );
//if( ! tcp_send( session->sock_obj, stanza2 ) ) {
if( socket_send( session->sock_id, stanza2 ) ) {
@@ -228,8 +225,7 @@
/* the first Jabber connect stanza */
size1 = 100 + strlen( server );
char stanza1[ size1 ];
- memset( stanza1, 0, size1 );
- sprintf( stanza1,
+ snprintf( stanza1, sizeof(stanza1),
"<stream:stream to='%s' xmlns='jabber:client' "
"xmlns:stream='http://etherx.jabber.org/streams'>",
server );
@@ -253,9 +249,7 @@
/* the second jabber connect stanza including login info*/
size2 = 150 + strlen( username ) + strlen(password) + strlen(resource);
char stanza2[ size2 ];
- memset( stanza2, 0, size2 );
-
- sprintf( stanza2,
+ snprintf( stanza2, sizeof(stanza2),
"<iq id='123456789' type='set'><query xmlns='jabber:iq:auth'>"
"<username>%s</username><password>%s</password><resource>%s</resource></query></iq>",
username, password, resource );
@@ -273,17 +267,14 @@
int ss = session->session_id->n_used + strlen(password) + 5;
char hashstuff[ss];
- memset(hashstuff,0,ss);
- sprintf( hashstuff, "%s%s", session->session_id->buf, password );
+ snprintf( hashstuff, sizeof(hashstuff), "%s%s", session->session_id->buf, password );
char* hash = shahash( hashstuff );
/* the second jabber connect stanza including login info*/
size2 = 150 + strlen( hash ) + strlen(password) + strlen(resource);
char stanza2[ size2 ];
- memset( stanza2, 0, size2 );
-
- sprintf( stanza2,
+ snprintf( stanza2, sizeof(stanza2),
"<iq id='123456789' type='set'><query xmlns='jabber:iq:auth'>"
"<username>%s</username><digest>%s</digest><resource>%s</resource></query></iq>",
username, hash, resource );
@@ -566,7 +557,6 @@
void *session, const xmlChar *ch, int len) {
char data[len+1];
- memset( data, 0, len+1 );
strncpy( data, (char*) ch, len );
data[len] = 0;
@@ -597,7 +587,7 @@
if( ses->state_machine->in_error ) {
/* for now... */
- osrfLogWarning( OSRF_LOG_MARK, "ERROR Xml fragment: %s\n", ch );
+ osrfLogWarning( OSRF_LOG_MARK, "ERROR XML fragment: %s\n", ch );
}
}
Modified: trunk/src/libopensrf/utils.c
===================================================================
--- trunk/src/libopensrf/utils.c 2007-09-30 18:53:17 UTC (rev 1097)
+++ trunk/src/libopensrf/utils.c 2007-09-30 19:14:26 UTC (rev 1098)
@@ -45,8 +45,9 @@
int i = 0;
while( i < argc ) {
int len = strlen( global_argv[i]);
- bzero( global_argv[i++], len );
+ memset( global_argv[i], 0, len);
global_argv_size += len;
+ i++;
}
global_argv_size -= 2;
@@ -55,7 +56,7 @@
int set_proc_title( char* format, ... ) {
VA_LIST_TO_STRING(format);
- bzero( *(global_argv), global_argv_size );
+ memset( *(global_argv), 0, global_argv_size);
return snprintf( *(global_argv), global_argv_size, VA_BUF );
}
@@ -121,7 +122,7 @@
len = va_list_size(format, args);
char buf[len];
- memset(buf, 0, len);
+ memset(buf, 0, sizeof(buf));
va_start(a_copy, format);
vsnprintf(buf, len - 1, format, a_copy);
@@ -164,7 +165,7 @@
len = va_list_size(format, args);
char buf[len];
- memset(buf, 0, len);
+ memset(buf, 0, sizeof(buf));
va_start(a_copy, format);
vsnprintf(buf, len - 1, format, a_copy);
@@ -212,7 +213,7 @@
int buffer_reset( growing_buffer *gb){
if( gb == NULL ) { return 0; }
if( gb->buf == NULL ) { return 0; }
- memset( gb->buf, 0, gb->size );
+ memset( gb->buf, 0, sizeof(gb->buf) );
gb->n_used = 0;
return 1;
}
@@ -416,7 +417,7 @@
int len = 1024;
char buf[len];
- bzero(buf, len);
+ memset(buf, 0, sizeof(buf));
growing_buffer* gb = buffer_init(len);
FILE* file = fopen(filename, "r");
@@ -425,9 +426,9 @@
return NULL;
}
- while(fgets(buf, len - 1, file)) {
+ while(fgets(buf, sizeof(buf), file)) {
buffer_add(gb, buf);
- bzero(buf, len);
+ memset(buf, 0, sizeof(buf));
}
fclose(file);
@@ -454,13 +455,11 @@
MD5_stop (&ctx, digest);
char buf[16];
- memset(buf,0,16);
-
char final[256];
- memset(final,0,256);
+ memset(final, 0, sizeof(final));
for ( i=0 ; i<16 ; i++ ) {
- sprintf(buf, "%02x", digest[i]);
+ snprintf(buf, sizeof(buf), "%02x", digest[i]);
strcat( final, buf );
}
Modified: trunk/src/objson/json_parser.c
===================================================================
--- trunk/src/objson/json_parser.c 2007-09-30 18:53:17 UTC (rev 1097)
+++ trunk/src/objson/json_parser.c 2007-09-30 19:14:26 UTC (rev 1098)
@@ -482,7 +482,7 @@
"json_parse_json_string(): truncated escaped unicode"); }
char buff[5];
- memset(buff,0,5);
+ memset(buff, 0, sizeof(buff));
memcpy(buff, string + (*index), 4);
@@ -491,7 +491,7 @@
/* The following chunk was borrowed with permission from
json-c http://oss.metaparadigm.com/json-c/ */
unsigned char utf_out[4];
- memset(utf_out,0,4);
+ memset(utf_out, 0, sizeof(utf_out));
#define hexdigit(x) ( ((x) <= '9') ? (x) - '0' : ((x) & 7) + 9)
@@ -695,7 +695,7 @@
int json_handle_error(char* string, unsigned long* index, char* err_msg) {
char buf[60];
- memset(buf, 0, 60);
+ memset(buf, 0, sizeof(buf));
if(*index > 30)
strncpy( buf, string + (*index - 30), 59 );
Modified: trunk/src/objson/objson_test.c
===================================================================
--- trunk/src/objson/objson_test.c 2007-09-30 18:53:17 UTC (rev 1097)
+++ trunk/src/objson/objson_test.c 2007-09-30 19:14:26 UTC (rev 1098)
@@ -183,11 +183,11 @@
char buf[10240];
char smallbuf[512];
- bzero(buf, 10240);
- bzero(smallbuf, 512);
+ memset(buf, 0, sizeof(buf));
+ memset(smallbuf, 0, sizeof(smallbuf));
- while(fgets(smallbuf, 512, F))
- strcat(buf, smallbuf);
+ while(fgets(smallbuf, sizeof(smallbuf), F))
+ strncat(buf, smallbuf, sizeof(buf) - 1);
/* dig our way into the JSON object we parsed, see test.json to get
an idea of the object structure */
Modified: trunk/src/router/osrf_router.c
===================================================================
--- trunk/src/router/osrf_router.c 2007-09-30 18:53:17 UTC (rev 1097)
+++ trunk/src/router/osrf_router.c 2007-09-30 19:14:26 UTC (rev 1098)
@@ -119,7 +119,7 @@
/* if the sender is not a trusted server, drop the message */
int len = strlen(msg->sender) + 1;
char domain[len];
- bzero(domain, len);
+ memset(domain, 0, sizeof(domain));
jid_get_domain( msg->sender, domain, len - 1 );
if(osrfStringArrayContains( router->trustedServers, domain))
@@ -150,7 +150,7 @@
/* if the client is not from a trusted domain, drop the message */
int len = strlen(msg->sender) + 1;
char domain[len];
- bzero(domain, len);
+ memset(domain, 0, sizeof(domain));
jid_get_domain( msg->sender, domain, len - 1 );
if(osrfStringArrayContains( router->trustedClients, domain)) {
@@ -486,7 +486,7 @@
int T = 32;
osrfMessage* arr[T];
- memset(arr, 0, T );
+ memset(arr, 0, sizeof(arr));
int num_msgs = osrf_message_deserialize( msg->body, arr, T );
osrfMessage* omsg = NULL;
@@ -520,7 +520,7 @@
osrfMessage* success = osrf_message_init( STATUS, omsg->thread_trace, omsg->protocol );
- osrfLogDebug( OSRF_LOG_MARK, "router recevied a CONNECT message from %s", msg->sender );
+ osrfLogDebug( OSRF_LOG_MARK, "router received a CONNECT message from %s", msg->sender );
osrf_message_set_status_info(
success, "osrfConnectStatus", "Connection Successful", OSRF_STATUS_OK );
Modified: trunk/src/srfsh/srfsh.c
===================================================================
--- trunk/src/srfsh/srfsh.c 2007-09-30 18:53:17 UTC (rev 1097)
+++ trunk/src/srfsh/srfsh.c 2007-09-30 19:14:26 UTC (rev 1098)
@@ -80,8 +80,7 @@
char* home = getenv("HOME");
int l = strlen(home) + 36;
char fbuf[l];
- memset(fbuf, 0, l);
- sprintf(fbuf,"%s/.srfsh.xml",home);
+ snprintf(fbuf, sizeof(fbuf), "%s/.srfsh.xml", home);
if(!access(fbuf, R_OK)) {
if( ! osrf_system_bootstrap_client(fbuf, "srfsh") ) {
@@ -193,9 +192,7 @@
char* home = getenv("HOME");
int l = strlen(home) + 24;
char fbuf[l];
-
- memset(fbuf, 0, l);
- sprintf(fbuf,"%s/.srfsh_history",home);
+ snprintf(fbuf, sizeof(fbuf), "%s/.srfsh_history", home);
history_file = strdup(fbuf);
if(!access(history_file, W_OK | R_OK )) {
@@ -322,14 +319,14 @@
static const char text[] = "request %s opensrf.system.method %s";
len = sizeof( text ) + strlen( words[1] ) + strlen( words[2] );
char buf[len];
- sprintf( buf, text, words[1], words[2] );
+ snprintf( buf, sizeof(buf), text, words[1], words[2] );
return parse_request( buf );
} else {
static const char text[] = "request %s opensrf.system.method.all";
len = sizeof( text ) + strlen( words[1] );
char buf[len];
- sprintf( buf, text, words[1] );
+ snprintf( buf, sizeof(buf), text, words[1] );
return parse_request( buf );
}
@@ -349,11 +346,10 @@
if(!type) type = "opac";
char login_text[] = "request open-ils.auth open-ils.auth.authenticate.init \"%s\"";
- size_t len = sizeof( login_text ) + strlen(username);
+ size_t len = sizeof( login_text ) + strlen(username) + 1;
char buf[len];
- buf[0] = '\0';
- sprintf( buf, login_text, username );
+ snprintf( buf, sizeof(buf), login_text, username );
parse_request(buf);
const char* hash;
@@ -367,8 +363,7 @@
size_t both_len = strlen( hash ) + strlen( pass_buf ) + 1;
char both_buf[both_len];
- both_buf[0] = '\0';
- sprintf(both_buf,"%s%s",hash, pass_buf);
+ snprintf(both_buf, sizeof(both_buf), "%s%s", hash, pass_buf);
char* mess_buf = md5sum(both_buf);
@@ -629,8 +624,7 @@
} else {
char code[16];
- memset(code, 0, 16);
- sprintf( code, "%d", omsg->status_code );
+ snprintf( code, sizeof(code), "%d", omsg->status_code );
buffer_add( resp_buffer, code );
printf( "\nReceived Exception:\nName: %s\nStatus: %s\nStatus: %s\n",
@@ -674,8 +668,7 @@
buffer_add( resp_buffer, omsg->status_text );
buffer_add( resp_buffer, "\nStatus: " );
char code[16];
- memset(code, 0, 16);
- sprintf( code, "%d", omsg->status_code );
+ snprintf( code, sizeof(code), "%d", omsg->status_code );
buffer_add( resp_buffer, code );
}
}
@@ -727,10 +720,9 @@
return 0;
const static char router_text[] = "router@%s/router";
- size_t len = sizeof( router_text ) + strlen( router_server );
+ size_t len = sizeof( router_text ) + strlen( router_server ) + 1;
char rbuf[len];
- rbuf[0] = '\0';
- sprintf(rbuf, router_text, router_server );
+ snprintf(rbuf, sizeof(rbuf), router_text, router_server );
transport_message* send =
message_init( "servers", NULL, NULL, rbuf, NULL );
@@ -849,7 +841,7 @@
char* answers[] = { "3", "-1", "2", "0.500000" };
float times[ count * 4 ];
- memset(times,0,count*4);
+ memset(times, 0, sizeof(times));
int k;
for(k=0;k!=100;k++) {
More information about the opensrf-commits
mailing list