]> sourceware.org Git - systemtap.git/commitdiff
Make sure print_[u]stack result is terminated.
authorMark Wielaard <mjw@redhat.com>
Mon, 5 Jul 2010 10:58:44 +0000 (12:58 +0200)
committerMark Wielaard <mjw@redhat.com>
Mon, 5 Jul 2010 10:58:44 +0000 (12:58 +0200)
Last line shouldn't have a newline and string should always be terminated.

* tapset/context-symbols.stp (sprint_stack): Terminate string.
* tapset/ucontext-symbols.stp (sprint_ustack): Likewise.

tapset/context-symbols.stp
tapset/ucontext-symbols.stp

index 091214bd7edec8d5fcf90796d0086cf88da9ee4e..9bb0f2479494688f80218052a5e46f3beb0edc4d 100644 (file)
@@ -50,7 +50,7 @@ function print_stack(stk:string) %{
  * Perform a symbolic lookup of the addresses in the given string,
  * which is assumed to be the result of a prior call to backtrace().
  *
- * Prints a simple backtrace from the given hex string. One line per
+ * Returns a simple backtrace from the given hex string. One line per
  * address. Includes the symbol name (or hex address if symbol
  * couldn't be resolved) and module name (if found). Includes the
  * offset from the start of the function if found, otherwise the
@@ -73,6 +73,12 @@ function sprint_stack:string(stk:string) %{
                str += s;
                tok = strsep(&ptr, " ");
        }
+
+        str--;
+        if (len > 0)
+                str[0] = '\0';
+        else
+                THIS->__retvalue[MAXSTRINGLEN - 1] = '\0';
 %}
 
 /**
index ecc387d63e8346e0f364357f4829cc247bee9ba5..a30089953de407f1f8b690f3d029dd0237819519 100644 (file)
@@ -85,7 +85,7 @@ function print_ustack(stk:string) %{
  * which is assumed to be the result of a prior call to
  * ubacktrace() for the current task.
  *
- * Prints a simple backtrace from the given hex string. One line per
+ * Returns a simple backtrace from the given hex string. One line per
  * address. Includes the symbol name (or hex address if symbol
  * couldn't be resolved) and module name (if found). Includes the
  * offset from the start of the function if found, otherwise the
@@ -101,11 +101,17 @@ function sprint_ustack:string(stk:string) %{
        char *str = THIS->__retvalue;
        size_t len = MAXSTRINGLEN - 1;
        while (tok && *tok && len > 0) {
-       int s = _stp_snprint_addr(str, len,
-               simple_strtol(tok, NULL, 16),
-                             _STP_SYM_SIMPLE, current);
+               int s = _stp_snprint_addr(str, len,
+                                         simple_strtol(tok, NULL, 16),
+                                         _STP_SYM_SIMPLE, current);
                len -= s;
                str += s;
                tok = strsep(&ptr, " ");
        }
+
+       str--;
+       if (len > 0)
+               str[0] = '\0';
+       else
+               THIS->__retvalue[MAXSTRINGLEN - 1] = '\0';
 %}
This page took 0.031094 seconds and 5 git commands to generate.