summaryrefslogtreecommitdiff
path: root/src/asn1Coding.c
diff options
context:
space:
mode:
authorPawel Kowalski <p.kowalski2@partner.samsung.com>2019-08-28 14:31:23 +0200
committerPawel Kowalski <p.kowalski2@partner.samsung.com>2019-08-28 16:56:31 +0200
commitdee455252ad321c660b411b4ecd65aa5e08f8fc1 (patch)
treeb55f9ec039e963e42605e9e9bdc186354cf9df42 /src/asn1Coding.c
parent5c7e0aaf17a296535495e3431db6a86ad64064b3 (diff)
parent26bea900a531662c6028ecc06f4adea825658434 (diff)
downloadlibtasn1-tizen_5.5_wearable_hotfix.tar.gz
libtasn1-tizen_5.5_wearable_hotfix.tar.bz2
libtasn1-tizen_5.5_wearable_hotfix.zip
Change-Id: I6d4b47b2072db8e7c45daa6e269e2f0cc6f54a7f
Diffstat (limited to 'src/asn1Coding.c')
-rw-r--r--src/asn1Coding.c51
1 files changed, 37 insertions, 14 deletions
diff --git a/src/asn1Coding.c b/src/asn1Coding.c
index b516bfe..86c1d07 100644
--- a/src/asn1Coding.c
+++ b/src/asn1Coding.c
@@ -25,11 +25,11 @@
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
+#include <assert.h>
#include <libtasn1.h>
-#include <progname.h>
-#include <version-etc.h>
+#define program_name "asn1Coding"
/* This feature is available in gcc versions 2.5 and later. */
#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
@@ -57,7 +57,7 @@ Mandatory arguments to long options are mandatory for short options too.\n\
-o, --output=FILE output file\n\
-h, --help display this help and exit\n\
-v, --version output version information and exit\n");
- emit_bug_reporting_address ();
+ printf ("Report bugs to "PACKAGE_BUGREPORT);
}
exit (status);
}
@@ -111,6 +111,12 @@ createFileName (char *inputFileName, char **outputFileName)
/* outputFileName= inputFileName + .out */
*outputFileName = (char *) malloc (dot_p - inputFileName + 1 +
strlen (".out"));
+ if (*outputFileName == NULL)
+ {
+ fprintf(stderr, "Memory error\n");
+ exit(1);
+ }
+
memcpy (*outputFileName, inputFileName, dot_p - inputFileName);
(*outputFileName)[dot_p - inputFileName] = 0;
strcat (*outputFileName, ".out");
@@ -146,8 +152,6 @@ main (int argc, char *argv[])
int k;
int last_ra;
- set_program_name (argv[0]);
-
opterr = 0; /* disable error messages from getopt */
while (1)
@@ -166,8 +170,9 @@ main (int argc, char *argv[])
usage (EXIT_SUCCESS);
break;
case 'v': /* VERSION */
- version_etc (stdout, program_name, PACKAGE, VERSION,
- "Fabio Fiorina", NULL);
+ printf(program_name" "PACKAGE" " VERSION"\n");
+ printf("Copyright (C) 2017-2019 Free Software Foundation, Inc.\n\n");
+ printf("Written by Fabio Fiorina\n");
free (outputFileName);
exit (0);
break;
@@ -175,8 +180,13 @@ main (int argc, char *argv[])
checkSyntaxOnly = 1;
break;
case 'o': /* OUTPUT */
- outputFileName = (char *) malloc (strlen (optarg) + 1);
- strcpy (outputFileName, optarg);
+ assert(optarg != NULL);
+ outputFileName = strdup(optarg);
+ if (outputFileName == NULL)
+ {
+ fprintf(stderr, "Memory error\n");
+ exit(1);
+ }
break;
case '?': /* UNKNOW OPTION */
free (outputFileName);
@@ -199,11 +209,19 @@ main (int argc, char *argv[])
usage (EXIT_FAILURE);
}
- inputFileAsnName = (char *) malloc (strlen (argv[optind]) + 1);
- strcpy (inputFileAsnName, argv[optind]);
+ inputFileAsnName = strdup(argv[optind]);
+ if (inputFileAsnName == NULL)
+ {
+ fprintf(stderr, "Memory error\n");
+ exit(1);
+ }
- inputFileAssignmentName = (char *) malloc (strlen (argv[optind + 1]) + 1);
- strcpy (inputFileAssignmentName, argv[optind + 1]);
+ inputFileAssignmentName = strdup(argv[optind+1]);
+ if (inputFileAssignmentName == NULL)
+ {
+ fprintf(stderr, "Memory error\n");
+ exit(1);
+ }
asn1_result =
asn1_parser2tree (inputFileAsnName, &definitions, errorDescription);
@@ -289,11 +307,16 @@ main (int argc, char *argv[])
asn1_print_structure (stderr, structure, "", ASN1_PRINT_NAME_TYPE_VALUE);
der_len = 0;
- asn1_result = asn1_der_coding (structure, "", der, &der_len,
+ asn1_result = asn1_der_coding (structure, "", NULL, &der_len,
errorDescription);
if (asn1_result == ASN1_MEM_ERROR)
{
der = malloc (der_len);
+ if (der == NULL)
+ {
+ fprintf(stderr, "Memory error\n");
+ exit(1);
+ }
asn1_result = asn1_der_coding (structure, "", der, &der_len,
errorDescription);
}