diff options
author | Tobias Stoeckmann <tobias@stoeckmann.org> | 2014-11-16 19:24:15 +0100 |
---|---|---|
committer | Andreas Gruenbacher <agruen@linbit.com> | 2014-11-30 15:35:44 +0100 |
commit | e4c6511f4660047957cd5be4e76964542e2d9447 (patch) | |
tree | cbca972b12e8097e6c5401696f2be671c6a75b17 | |
parent | 3fd4144ae983cc8a7398ba6aa830f71e779bbdfd (diff) | |
download | patch-e4c6511f4660047957cd5be4e76964542e2d9447.tar.gz |
savebuf/savestr error handling
* src/patch.c (get_some_switches): The function savebuf (and therefore savestr)
copies strings using malloc. If malloc fails, NULL is returned. This is
intentional behavior so that in case of failure during "plan a" patching, "plan
b" can step in. The return value has to be properly checked for NULL. If the
return value must not be NULL, use xstrdup instead.
-rw-r--r-- | src/patch.c | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/src/patch.c b/src/patch.c index 12028a9..adb2f25 100644 --- a/src/patch.c +++ b/src/patch.c @@ -865,7 +865,7 @@ get_some_switches (void) case 'B': if (!*optarg) fatal ("backup prefix is empty"); - origprae = savestr (optarg); + origprae = xstrdup (optarg); break; case 'c': diff_type = CONTEXT_DIFF; @@ -875,7 +875,7 @@ get_some_switches (void) pfatal ("Can't change to directory %s", quotearg (optarg)); break; case 'D': - do_defines = savestr (optarg); + do_defines = xstrdup (optarg); break; case 'e': diff_type = ED_DIFF; @@ -893,7 +893,7 @@ get_some_switches (void) patch_get = numeric_string (optarg, true, "get option value"); break; case 'i': - patchname = savestr (optarg); + patchname = xstrdup (optarg); break; case 'l': canonicalize = true; @@ -921,13 +921,13 @@ get_some_switches (void) noreverse = true; break; case 'o': - outfile = savestr (optarg); + outfile = xstrdup (optarg); break; case 'p': strippath = numeric_string (optarg, false, "strip count"); break; case 'r': - rejname = savestr (optarg); + rejname = xstrdup (optarg); break; case 'R': reverse = true; @@ -961,13 +961,13 @@ get_some_switches (void) case 'Y': if (!*optarg) fatal ("backup basename prefix is empty"); - origbase = savestr (optarg); + origbase = xstrdup (optarg); break; case 'z': case_z: if (!*optarg) fatal ("backup suffix is empty"); - origsuff = savestr (optarg); + origsuff = xstrdup (optarg); break; case 'Z': set_utc = true; @@ -1036,12 +1036,12 @@ get_some_switches (void) /* Process any filename args. */ if (optind < Argc) { - inname = savestr (Argv[optind++]); + inname = xstrdup (Argv[optind++]); explicit_inname = true; invc = -1; if (optind < Argc) { - patchname = savestr (Argv[optind++]); + patchname = xstrdup (Argv[optind++]); if (optind < Argc) { fprintf (stderr, "%s: %s: extra operand\n", |