]> git.ipfire.org Git - thirdparty/mtr.git/commitdiff
Fixed some irritating compiler warnings
authorR.E. Wolff <R.E.Wolff@BitWizard.nl>
Fri, 8 May 2026 11:37:00 +0000 (13:37 +0200)
committerR.E. Wolff <R.E.Wolff@BitWizard.nl>
Fri, 8 May 2026 11:37:00 +0000 (13:37 +0200)
packet/probe.c
ui/split.c

index 4b265af47cc82918feab22a5720d0e2b4875bc65..904f0d129bf7d1d7f4fd6d0fc3b565e8c4d6a4db 100644 (file)
@@ -257,7 +257,6 @@ void respond_to_probe(
     char ip_text[INET6_ADDRSTRLEN];
     char response[COMMAND_BUFFER_SIZE];
     char mpls_str[COMMAND_BUFFER_SIZE];
-    int remaining_size;
     const char *result;
     const char *ip_argument;
 
@@ -286,6 +285,10 @@ void respond_to_probe(
              "%d %s %s %s round-trip-time %d",
              probe->token, result, ip_argument, ip_text, round_trip_us);
 
+#if 0
+// This is the old code. I think the new code should do the same, but to be
+// sure, I want one commit with both versions side-by-side. 
+    int remaining_size;
     if (mpls_count) {
         format_mpls_string(mpls_str, COMMAND_BUFFER_SIZE, mpls_count,
                            mpls);
@@ -296,6 +299,19 @@ void respond_to_probe(
         remaining_size = COMMAND_BUFFER_SIZE - strlen(response) - 1;
         strncat(response, mpls_str, remaining_size);
     }
+#else
+    if (mpls_count) {
+        format_mpls_string(mpls_str, COMMAND_BUFFER_SIZE, mpls_count, mpls);
+
+        // Get the current length to use as an offset
+        size_t current_len = strlen(response);
+
+        // snprintf returns the number of chars it *would* have written, 
+        // but it safely stops at COMMAND_BUFFER_SIZE - 1.
+        snprintf(response + current_len, COMMAND_BUFFER_SIZE - current_len, 
+             " mpls %s", mpls_str);
+    }
+#endif
 
     puts(response);
     free_probe(net_state, probe);
index a22131813125e51738f66e36a351fde3029ed72e..0b909dd663598285756d72da9e245e439227a27a 100644 (file)
@@ -55,7 +55,7 @@
 
 /* There is 256 hops max in the IP header (coded with a byte) */
 #define MAX_LINE_COUNT 256
-#define MAX_LINE_SIZE  256
+#define MAX_LINE_SIZE  1024
 
 static char Lines[MAX_LINE_COUNT][MAX_LINE_SIZE];
 static int LineCount;
@@ -114,7 +114,8 @@ void split_redraw(
            // something changed, so we print it.
             printf("%d %s\n", at + 1, newLine);
             fflush(stdout);
-            xstrncpy(Lines[at], newLine, MAX_LINE_SIZE);
+           // xstrncpy(Lines[at], newLine, MAX_LINE_SIZE);
+            snprintf(Lines[at], MAX_LINE_SIZE, "%s", newLine);
             if (LineCount < (at + 1)) {
                 LineCount = at + 1;
             }