shithub: sox

Download patch

ref: 9efe110d8320d941d82ab004320f973963743973
parent: 7ca19868aa8675d25238f7688b5c981abbff1778
author: Ulrich Klauer <ulrich@chirlu.de>
date: Sun Jan 1 19:00:10 EST 2012

Use lsx_strdup to copy strings

Fix a few cases where lsx_malloc+strlen+strcpy were used directly
instead of the lsx_strdup macro.

--- a/src/fade.c
+++ b/src/fade.c
@@ -73,8 +73,7 @@
         fade->out_fadetype = 'l';
     }
 
-    fade->in_stop_str = lsx_malloc(strlen(argv[0])+1);
-    strcpy(fade->in_stop_str,argv[0]);
+    fade->in_stop_str = lsx_strdup(argv[0]);
     /* Do a dummy parse to see if it will fail */
     n = lsx_parsesamples(0., fade->in_stop_str, &samples, 't');
     if (!n || *n)
@@ -88,8 +87,7 @@
         /* See if there is fade-in/fade-out times/curves specified. */
         if(t_argno == 1)
         {
-            fade->out_stop_str = lsx_malloc(strlen(argv[t_argno])+1);
-            strcpy(fade->out_stop_str,argv[t_argno]);
+            fade->out_stop_str = lsx_strdup(argv[t_argno]);
 
             /* Do a dummy parse to see if it will fail */
             n = lsx_parsesamples(0., fade->out_stop_str, &samples, 't');
@@ -99,8 +97,7 @@
         }
         else
         {
-            fade->out_start_str = lsx_malloc(strlen(argv[t_argno])+1);
-            strcpy(fade->out_start_str,argv[t_argno]);
+            fade->out_start_str = lsx_strdup(argv[t_argno]);
 
             /* Do a dummy parse to see if it will fail */
             n = lsx_parsesamples(0., fade->out_start_str, &samples, 't');
--- a/src/silence.c
+++ b/src/silence.c
@@ -118,8 +118,7 @@
          * parse the duration info yet.  So save argument off
          * for future processing.
          */
-        silence->start_duration_str = lsx_malloc(strlen(argv[0])+1);
-        strcpy(silence->start_duration_str,argv[0]);
+        silence->start_duration_str = lsx_strdup(argv[0]);
         /* Perform a fake parse to do error checking */
         n = lsx_parsesamples(0.,silence->start_duration_str,&silence->start_duration,'s');
         if (!n || *n)
@@ -159,8 +158,7 @@
          * parse the duration info yet.  So save argument off
          * for future processing.
          */
-        silence->stop_duration_str = lsx_malloc(strlen(argv[0])+1);
-        strcpy(silence->stop_duration_str,argv[0]);
+        silence->stop_duration_str = lsx_strdup(argv[0]);
         /* Perform a fake parse to do error checking */
         n = lsx_parsesamples(0.,silence->stop_duration_str,&silence->stop_duration,'s');
         if (!n || *n)
--- a/src/synth.c
+++ b/src/synth.c
@@ -302,8 +302,7 @@
 
   /* Get duration if given (if first arg starts with digit) */
   if (argc && (isdigit((int)argv[argn][0]) || argv[argn][0] == '.')) {
-    p->length_str = lsx_malloc(strlen(argv[argn]) + 1);
-    strcpy(p->length_str, argv[argn]);
+    p->length_str = lsx_strdup(argv[argn]);
     /* Do a dummy parse of to see if it will fail */
     n = lsx_parsesamples(0., p->length_str, &p->samples_to_do, 't');
     if (!n || *n)
--- a/src/trim.c
+++ b/src/trim.c
@@ -45,8 +45,7 @@
                 trim->end_is_absolute = sox_true;
                 end++;
             } else trim->end_is_absolute = sox_false;
-            trim->end_str = lsx_malloc(strlen(end)+1);
-            strcpy(trim->end_str, end);
+            trim->end_str = lsx_strdup(end);
             /* Do a dummy parse to see if it will fail */
             n = lsx_parsesamples(0., trim->end_str, &samples, 't');
             if (!n || *n)
@@ -53,8 +52,7 @@
               return lsx_usage(effp);
             trim->length = samples;
         case 1:
-            trim->start_str = lsx_malloc(strlen(argv[0])+1);
-            strcpy(trim->start_str,argv[0]);
+            trim->start_str = lsx_strdup(argv[0]);
             /* Do a dummy parse to see if it will fail */
             n = lsx_parsesamples(0., trim->start_str, &samples, 't');
             if (!n || *n)