[augeas-devel] augeas: master - * src/info.c (format_info): minor fixes

David Lutterkort lutter at fedoraproject.org
Thu Oct 1 00:23:48 UTC 2009


Gitweb:        http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=41ba8d6a05beafc4ab8f9d7ecf99ad1d8d505a7f
Commit:        41ba8d6a05beafc4ab8f9d7ecf99ad1d8d505a7f
Parent:        0a9edaca7b76cdc389859b9b52507f4455484a64
Author:        David Lutterkort <lutter at redhat.com>
AuthorDate:    Wed Sep 30 16:58:11 2009 -0700
Committer:     David Lutterkort <lutter at redhat.com>
CommitterDate: Wed Sep 30 17:20:38 2009 -0700

* src/info.c (format_info): minor fixes

  - append a ':' after the location
  - produce a result even when line numbers are invalid
  - use xasprintf, not asprintf
---
 src/info.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/info.c b/src/info.c
index 429e2a2..278fb60 100644
--- a/src/info.c
+++ b/src/info.c
@@ -60,7 +60,7 @@ void free_string(struct string *string) {
  */
 char *format_info(struct info *info) {
     const char *fname;
-    char *result;
+    char *result = NULL;
     int r = 0;
     int fl = info->first_line, ll = info->last_line;
     int fc = info->first_column, lc = info->last_column;
@@ -69,13 +69,15 @@ char *format_info(struct info *info) {
     if (fl > 0) {
         if (fl == ll) {
             if (fc == lc) {
-                r = asprintf(&result, "%s:%d.%d", fname, fl, fc);
+                r = xasprintf(&result, "%s:%d.%d:", fname, fl, fc);
             } else {
-                r = asprintf(&result, "%s:%d.%d-.%d", fname, fl, fc, lc);
+                r = xasprintf(&result, "%s:%d.%d-.%d:", fname, fl, fc, lc);
             }
         } else {
-            r = asprintf(&result, "%s:%d.%d-%d.%d", fname, fl, fc, ll, lc);
+            r = xasprintf(&result, "%s:%d.%d-%d.%d:", fname, fl, fc, ll, lc);
         }
+    } else {
+        r = xasprintf(&result, "%s:", fname);
     }
     return (r == -1) ? NULL : result;
 }




More information about the augeas-devel mailing list