4
4
5
5
/* System */
6
6
7
+ #include <bits/getopt_core.h>
7
8
#include <errno.h>
8
9
#include <fcntl.h>
9
10
#include <getopt.h>
@@ -77,7 +78,7 @@ struct cli_options cli_options = {
77
78
.gap_partition = EPT_PARTITION_GAP_GENERIC ,
78
79
.gap_reserved = EPT_PARTITION_GAP_RESERVED ,
79
80
.size = 0 ,
80
- .target = NULL
81
+ .target = ""
81
82
};
82
83
83
84
/* Function */
@@ -302,6 +303,17 @@ cli_parse_options(
302
303
return 0 ;
303
304
}
304
305
306
+ static inline
307
+ void
308
+ cli_option_replace_target (
309
+ // struct cli_options *const restrict cli_options,
310
+ char const * const restrict target
311
+ ){
312
+ size_t len_target = strnlen (target , (sizeof cli_options .target ) - 1 );
313
+ memcpy (cli_options .target , target , len_target );
314
+ cli_options .target [len_target ] = '\0' ;
315
+ }
316
+
305
317
static inline
306
318
int
307
319
cli_find_disk (){
@@ -311,8 +323,8 @@ cli_find_disk(){
311
323
return 1 ;
312
324
}
313
325
pr_error ("CLI interface: Operating on '%s' instead, content type is now disk\n" , path_disk );
314
- free ( cli_options . target );
315
- cli_options . target = path_disk ;
326
+ cli_option_replace_target ( path_disk );
327
+ free ( path_disk ) ;
316
328
cli_options .content = CLI_CONTENT_TYPE_DISK ;
317
329
return 0 ;
318
330
}
@@ -384,11 +396,7 @@ cli_complete_options(
384
396
cli_options .write = CLI_WRITE_NOTHING ;
385
397
}
386
398
if (optind < argc ) {
387
- cli_options .target = strdup (argv [optind ++ ]);
388
- if (!cli_options .target ) {
389
- pr_error ("CLI interface: Failed to duplicate target string '%s'\n" , argv [optind - 1 ]);
390
- return 2 ;
391
- }
399
+ cli_option_replace_target (argv [optind ++ ]);
392
400
pr_error ("CLI interface: Operating on target file/block device '%s'\n" , cli_options .target );
393
401
int const r = cli_options_complete_target_info ();
394
402
if (r ) {
0 commit comments