[powerdebug V2: 02/14] save some bytes by allocating dynamically the string option

Daniel Lezcano daniel.lezcano at free.fr
Wed Mar 23 13:37:31 UTC 2011


Signed-off-by: Daniel Lezcano <daniel.lezcano at free.fr>
---
 powerdebug.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/powerdebug.c b/powerdebug.c
index efdb1a2..05c0e34 100644
--- a/powerdebug.c
+++ b/powerdebug.c
@@ -85,7 +85,7 @@ struct powerdebug_options {
 	int sensors;
 	int clocks;
 	int ticktime;
-	char clkarg[64];
+	char *clkarg;
 };
 
 int getoptions(int argc, char *argv[], struct powerdebug_options *options)
@@ -118,7 +118,11 @@ int getoptions(int argc, char *argv[], struct powerdebug_options *options)
 			break;
 		case 'p':
 			options->findparent = 1;
-			strcpy(options->clkarg, optarg);
+			options->clkarg = strdup(optarg);
+			if (!options->clkarg) {
+				fprintf(stderr, "failed to allocate memory");
+				return -1;
+			}
 			break;
 		case 't':
 			options->ticktime = strtod(optarg, NULL);
-- 
1.7.1




More information about the linaro-dev mailing list