--- projects/libstatgrab/src/libstatgrab/process_stats.c 2004/04/05 15:40:15 1.52 +++ projects/libstatgrab/src/libstatgrab/process_stats.c 2004/04/05 18:10:11 1.53 @@ -18,7 +18,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * 02111-1307 USA * - * $Id: process_stats.c,v 1.52 2004/04/05 15:40:15 ats Exp $ + * $Id: process_stats.c,v 1.53 2004/04/05 18:10:11 ats Exp $ */ #ifdef HAVE_CONFIG_H @@ -183,7 +183,7 @@ sg_process_stats *sg_get_process_stats(int *entries){ if(ptr !=NULL) *ptr='\0'; if (sg_update_string(&proc_state_ptr->process_name, - &ps_name[1]) == NULL) { + &ps_name[1]) < 0) { return NULL; } @@ -204,7 +204,7 @@ sg_process_stats *sg_get_process_stats(int *entries){ #define READ_BLOCK_SIZE 128 len = 0; do { - if (VECTOR_RESIZE(psargs, len + READ_BLOCK_SIZE + 1) < 0) { + if (VECTOR_RESIZE(psargs, len + READ_BLOCK_SIZE) < 0) { return NULL; } rc = read(fn, psargs + len, READ_BLOCK_SIZE); @@ -225,10 +225,21 @@ sg_process_stats *sg_get_process_stats(int *entries){ if (*ptr == '\0') *ptr = ' '; ptr++; } - /* for safety's sake */ - psargs[len] = '\0'; - if (sg_update_string(&proc_state_ptr->proctitle, psargs) == NULL) { + if (len == 0) { + /* We want psargs to be NULL. */ + if (VECTOR_RESIZE(psargs, 0) < 0) { + return NULL; + } + } else { + /* Not empty, so append a \0. */ + if (VECTOR_RESIZE(psargs, len + 1) < 0) { + return NULL; + } + psargs[len] = '\0'; + } + + if (sg_update_string(&proc_state_ptr->proctitle, psargs) < 0) { return NULL; } #endif @@ -278,7 +289,7 @@ sg_process_stats *sg_get_process_stats(int *entries){ #else name = kp_stats[i].kp_proc.p_comm; #endif - if (sg_update_string(&proc_state_ptr->process_name, name) == NULL) { + if (sg_update_string(&proc_state_ptr->process_name, name) < 0) { return NULL; }