unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Problem report #132 [1/2]: base/src/emacs/src/process.c (procfs_system_process_attributes); UNINIT
@ 2008-12-03  1:21 Dan Nicolaescu
  2008-12-05  7:11 ` Eli Zaretskii
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Nicolaescu @ 2008-12-03  1:21 UTC (permalink / raw)
  To: emacs-devel

CID: 132
Checker: UNINIT (help)
File: base/src/emacs/src/process.c
Function: procfs_system_process_attributes
Description: Using uninitialized value "cmdsize"

Event var_decl: Declared variable "cmdsize" without initializer
Also see events: [uninit_use]

7251 	  size_t cmdsize, cmdline_size;
7252 	  unsigned char c;
7253 	  int proc_id, ppid, uid, gid, pgrp, sess, tty, tpgid, thcount;
7254 	  unsigned long long utime, stime, cutime, cstime, start;
7255 	  long priority, nice, rss;
7256 	  unsigned long minflt, majflt, cminflt, cmajflt, vsize;
7257 	  time_t sec;
7258 	  unsigned usec;
7259 	  EMACS_TIME tnow, tstart, tboot, telapsed,ttotal;
7260 	  double pcpu, pmem;
7261 	  Lisp_Object attrs = Qnil;
7262 	  Lisp_Object cmd_str, decoded_cmd, tem;
7263 	  struct gcpro gcpro1, gcpro2;
7264 	  EMACS_INT uid_eint, gid_eint;
7265 	
7266 	  CHECK_NUMBER_OR_FLOAT (pid);
7267 	  proc_id = FLOATP (pid) ? XFLOAT_DATA (pid) : XINT (pid);
7268 	  sprintf (procfn, "/proc/%lu", proc_id);

At conditional (1): "stat < 0" taking false path

7269 	  if (stat (procfn, &st) < 0)
7270 	    return attrs;
7271 	
7272 	  GCPRO2 (attrs, decoded_cmd);
7273 	
7274 	  /* euid egid */
7275 	  uid = st.st_uid;
7276 	  /* Use of EMACS_INT stops GCC whining about limited range of data type.  */
7277 	  uid_eint = uid;

At conditional (2): "uid_eint > 1152921504606846975" taking true path

7278 	  attrs = Fcons (Fcons (Qeuid, make_fixnum_or_float (uid_eint)), attrs);
7279 	  BLOCK_INPUT;
7280 	  pw = getpwuid (uid);

At conditional (3): "interrupt_input_blocked == 0" taking true path
At conditional (4): "interrupt_input_pending != 0" taking true path
At conditional (5): "pending_atimers != 0" taking true path
At conditional (6): "0" taking false path

7281 	  UNBLOCK_INPUT;

At conditional (7): "pw != 0" taking true path

7282 	  if (pw)
7283 	    attrs = Fcons (Fcons (Quser, build_string (pw->pw_name)), attrs);
7284 	
7285 	  gid = st.st_gid;
7286 	  gid_eint = gid;

At conditional (8): "gid_eint > 1152921504606846975" taking true path

7287 	  attrs = Fcons (Fcons (Qegid, make_fixnum_or_float (gid_eint)), attrs);
7288 	  BLOCK_INPUT;
7289 	  gr = getgrgid (gid);

At conditional (9): "interrupt_input_blocked == 0" taking true path
At conditional (10): "interrupt_input_pending != 0" taking true path
At conditional (11): "pending_atimers != 0" taking true path
At conditional (12): "0" taking false path

7290 	  UNBLOCK_INPUT;

At conditional (13): "gr != 0" taking true path

7291 	  if (gr)
7292 	    attrs = Fcons (Fcons (Qgroup, build_string (gr->gr_name)), attrs);
7293 	
7294 	  strcpy (fn, procfn);
7295 	  procfn_end = fn + strlen (fn);
7296 	  strcpy (procfn_end, "/stat");
7297 	  fd = emacs_open (fn, O_RDONLY, 0);

At conditional (14): "fd >= 0" taking true path
At conditional (15): "nread = emacs_read > 0" taking false path

7298 	  if (fd >= 0 && (nread = emacs_read (fd, procbuf, sizeof(procbuf) - 1)) > 0)
7299 	    {
7300 	      procbuf[nread] = '\0';
7301 	      p = procbuf;
7302 	
7303 	      cmd = NULL;
7304 	      p = strchr (p, '(');
7305 	      if (p != NULL)
7306 		{
7307 		  q = strrchr (p + 1, ')');
7308 		  /* comm */
7309 		  if (q != NULL)
7310 		    {
7311 		      cmd = p + 1;
7312 		      cmdsize = q - cmd;
7313 		    }
7314 		}
7315 	      if (cmd == NULL)
7316 		{
7317 		  cmd = "???";
7318 		  cmdsize = 3;
7319 		}
7320 	      /* Command name is encoded in locale-coding-system; decode it.  */
7321 	      cmd_str = make_unibyte_string (cmd, cmdsize);
7322 	      decoded_cmd = code_convert_string_norecord (cmd_str,
7323 							  Vlocale_coding_system, 0);
7324 	      attrs = Fcons (Fcons (Qcomm, decoded_cmd), attrs);
7325 	
7326 	      if (q)
7327 		{
7328 		  EMACS_INT ppid_eint, pgrp_eint, sess_eint, tpgid_eint, thcount_eint;
7329 		  p = q + 2;
7330 		  /* state ppid pgrp sess tty tpgid . minflt cminflt majflt cmajflt utime stime cutime cstime priority nice thcount . start vsize rss */
7331 		  sscanf (p, "%c %d %d %d %d %d %*u %lu %lu %lu %lu %Lu %Lu %Lu %Lu %ld %ld %d %*d %Lu %lu %ld",
7332 			  &c, &ppid, &pgrp, &sess, &tty, &tpgid,
7333 			  &minflt, &cminflt, &majflt, &cmajflt,
7334 			  &utime, &stime, &cutime, &cstime,
7335 			  &priority, &nice, &thcount, &start, &vsize, &rss);
7336 		  {
7337 		    char state_str[2];
7338 	
7339 		    state_str[0] = c;
7340 		    state_str[1] = '\0';
7341 		    tem =  build_string (state_str);
7342 		    attrs = Fcons (Fcons (Qstate, tem), attrs);
7343 		  }
7344 		  /* Stops GCC whining about limited range of data type.  */
7345 		  ppid_eint = ppid;
7346 		  pgrp_eint = pgrp;
7347 		  sess_eint = sess;
7348 		  tpgid_eint = tpgid;
7349 		  thcount_eint = thcount;
7350 		  attrs = Fcons (Fcons (Qppid, make_fixnum_or_float (ppid_eint)), attrs);
7351 		  attrs = Fcons (Fcons (Qpgrp, make_fixnum_or_float (pgrp_eint)), attrs);
7352 		  attrs = Fcons (Fcons (Qsess, make_fixnum_or_float (sess_eint)), attrs);
7353 		  attrs = Fcons (Fcons (Qttname, procfs_ttyname (tty)), attrs);
7354 		  attrs = Fcons (Fcons (Qtpgid, make_fixnum_or_float (tpgid_eint)), attrs);
7355 		  attrs = Fcons (Fcons (Qminflt, make_fixnum_or_float (minflt)), attrs);
7356 		  attrs = Fcons (Fcons (Qmajflt, make_fixnum_or_float (majflt)), attrs);
7357 		  attrs = Fcons (Fcons (Qcminflt, make_fixnum_or_float (cminflt)), attrs);
7358 		  attrs = Fcons (Fcons (Qcmajflt, make_fixnum_or_float (cmajflt)), attrs);
7359 		  clocks_per_sec = sysconf (_SC_CLK_TCK);
7360 		  if (clocks_per_sec < 0)
7361 		    clocks_per_sec = 100;
7362 		  attrs = Fcons (Fcons (Qutime,
7363 					ltime_from_jiffies (utime, clocks_per_sec)),
7364 				 attrs);
7365 		  attrs = Fcons (Fcons (Qstime,
7366 					ltime_from_jiffies (stime, clocks_per_sec)),
7367 				 attrs);
7368 		  attrs = Fcons (Fcons (Qcutime,
7369 					ltime_from_jiffies (cutime, clocks_per_sec)),
7370 				 attrs);
7371 		  attrs = Fcons (Fcons (Qcstime,
7372 					ltime_from_jiffies (cstime, clocks_per_sec)),
7373 				 attrs);
7374 		  attrs = Fcons (Fcons (Qpri, make_number (priority)), attrs);
7375 		  attrs = Fcons (Fcons (Qnice, make_number (nice)), attrs);
7376 		  attrs = Fcons (Fcons (Qthcount, make_fixnum_or_float (thcount_eint)), attrs);
7377 		  EMACS_GET_TIME (tnow);
7378 		  get_up_time (&sec, &usec);
7379 		  EMACS_SET_SECS (telapsed, sec);
7380 		  EMACS_SET_USECS (telapsed, usec);
7381 		  EMACS_SUB_TIME (tboot, tnow, telapsed);
7382 		  time_from_jiffies (start, clocks_per_sec, &sec, &usec);
7383 		  EMACS_SET_SECS (tstart, sec);
7384 		  EMACS_SET_USECS (tstart, usec);
7385 		  EMACS_ADD_TIME (tstart, tboot, tstart);
7386 		  attrs = Fcons (Fcons (Qstart,
7387 					list3 (make_number
7388 					       ((EMACS_SECS (tstart) >> 16) & 0xffff),
7389 					       make_number
7390 					       (EMACS_SECS (tstart) & 0xffff),
7391 					       make_number
7392 					       (EMACS_USECS (tstart)))),
7393 				 attrs);
7394 		  attrs = Fcons (Fcons (Qvsize, make_fixnum_or_float (vsize/1024)), attrs);
7395 		  attrs = Fcons (Fcons (Qrss, make_fixnum_or_float (4*rss)), attrs);
7396 		  EMACS_SUB_TIME (telapsed, tnow, tstart);
7397 		  attrs = Fcons (Fcons (Qetime,
7398 					list3 (make_number
7399 					       ((EMACS_SECS (telapsed) >> 16) & 0xffff),
7400 					       make_number
7401 					       (EMACS_SECS (telapsed) & 0xffff),
7402 					       make_number
7403 					       (EMACS_USECS (telapsed)))),
7404 				 attrs);
7405 		  time_from_jiffies (utime + stime, clocks_per_sec, &sec, &usec);
7406 		  pcpu = (sec + usec / 1000000.0) / (EMACS_SECS (telapsed) + EMACS_USECS (telapsed) / 1000000.0);
7407 		  if (pcpu > 1.0)
7408 		    pcpu = 1.0;
7409 		  attrs = Fcons (Fcons (Qpcpu, make_float (100 * pcpu)), attrs);
7410 		  pmem = 4.0 * 100 * rss / procfs_get_total_memory ();
7411 		  if (pmem > 100)
7412 		    pmem = 100;
7413 		  attrs = Fcons (Fcons (Qpmem, make_float (pmem)), attrs);
7414 		}
7415 	    }

At conditional (16): "fd >= 0" taking true path

7416 	  if (fd >= 0)
7417 	    emacs_close (fd);
7418 	
7419 	  /* args */
7420 	  strcpy (procfn_end, "/cmdline");
7421 	  fd = emacs_open (fn, O_RDONLY, 0);

At conditional (17): "fd >= 0" taking true path

7422 	  if (fd >= 0)
7423 	    {

At conditional (18): "emacs_read == 1" taking true path
At conditional (20): "emacs_read == 1" taking false path

7424 	      for (cmdline_size = 0; emacs_read (fd, &c, 1) == 1; cmdline_size++)
7425 		{

At conditional (19): "*(*__ctype_b_loc + (c * 2)) & 8192 != 0" taking true path

7426 		  if (isspace (c) || c == '\\')
7427 		    cmdline_size++;	/* for later quoting, see below */
7428 		}

At conditional (21): "cmdline_size != 0" taking false path

7429 	      if (cmdline_size)
7430 		{
7431 		  cmdline = xmalloc (cmdline_size + 1);
7432 		  lseek (fd, 0L, SEEK_SET);
7433 		  cmdline[0] = '\0';
7434 		  if ((nread = read (fd, cmdline, cmdline_size)) >= 0)
7435 		    cmdline[nread++] = '\0';
7436 		  /* We don't want trailing null characters.  */
7437 		  for (p = cmdline + nread - 1; p > cmdline && !*p; p--)
7438 		    nread--;
7439 		  for (p = cmdline; p < cmdline + nread; p++)
7440 		    {
7441 		      /* Escape-quote whitespace and backslashes.  */
7442 		      if (isspace (*p) || *p == '\\')
7443 			{
7444 			  memmove (p + 1, p, nread - (p - cmdline));
7445 			  nread++;
7446 			  *p++ = '\\';
7447 			}
7448 		      else if (*p == '\0')
7449 			*p = ' ';
7450 		    }
7451 		  cmdline_size = nread;
7452 		}
7453 	      else
7454 		{

Event uninit_use: Using uninitialized value "cmdsize"
Also see events: [var_decl]

7455 		  cmdline_size = cmdsize + 2;
7456 		  cmdline = xmalloc (cmdline_size + 1);
7457 		  strcpy (cmdline, "[");
7458 		  strcat (strncat (cmdline, cmd, cmdsize), "]");
7459 		}
7460 	      emacs_close (fd);
7461 	      /* Command line is encoded in locale-coding-system; decode it.  */
7462 	      cmd_str = make_unibyte_string (cmdline, cmdline_size);
7463 	      decoded_cmd = code_convert_string_norecord (cmd_str,
7464 							  Vlocale_coding_system, 0);
7465 	      xfree (cmdline);
7466 	      attrs = Fcons (Fcons (Qargs, decoded_cmd), attrs);
7467 	    }
7468 	
7469 	  UNGCPRO;
7470 	  return attrs;
7471 	}
7472 	




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Problem report #132 [1/2]: base/src/emacs/src/process.c (procfs_system_process_attributes); UNINIT
  2008-12-03  1:21 Problem report #132 [1/2]: base/src/emacs/src/process.c (procfs_system_process_attributes); UNINIT Dan Nicolaescu
@ 2008-12-05  7:11 ` Eli Zaretskii
  0 siblings, 0 replies; 2+ messages in thread
From: Eli Zaretskii @ 2008-12-05  7:11 UTC (permalink / raw)
  To: Dan Nicolaescu; +Cc: emacs-devel

> From: Dan Nicolaescu <dann@ics.uci.edu>
> Date: Tue, 02 Dec 2008 17:21:27 -0800
> 
> CID: 132
> Checker: UNINIT (help)
> File: base/src/emacs/src/process.c
> Function: procfs_system_process_attributes
> Description: Using uninitialized value "cmdsize"

Fixed, thanks.




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-12-05  7:11 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-03  1:21 Problem report #132 [1/2]: base/src/emacs/src/process.c (procfs_system_process_attributes); UNINIT Dan Nicolaescu
2008-12-05  7:11 ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).