diff options
author | Jörg Frings-Fürst <debian@jff.email> | 2023-02-12 17:35:53 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff.email> | 2023-02-12 17:35:53 +0100 |
commit | 84357741a6a6e6430f199b2c3f7498e0e97da9ad (patch) | |
tree | 23e8d66ede9506b94c76fb36910ca3c7dd15c74e /backend/canon_pp.c | |
parent | 302276dc1b90cfc972fb726ca94a23b18f4b0088 (diff) |
New upstream version 1.2.1upstream/1.2.1upstream
Diffstat (limited to 'backend/canon_pp.c')
-rw-r--r-- | backend/canon_pp.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/backend/canon_pp.c b/backend/canon_pp.c index b933102..79c6c63 100644 --- a/backend/canon_pp.c +++ b/backend/canon_pp.c @@ -1787,7 +1787,9 @@ static int init_cal(char *file) ************************************************************************/ static SANE_Status fix_weights_file(CANONP_Scanner *cs) { - char *tmp, *myhome, buf[PATH_MAX]; + static const char default_weights_file_prefix[] = + "~/.sane/canon_pp-calibration-"; + char *tmp, *myhome; int i; struct stat *f_stat; @@ -1804,31 +1806,32 @@ static SANE_Status fix_weights_file(CANONP_Scanner *cs) if (cs->weights_file == NULL) { - /* Will be of form canon_pp-calibration-parport0 or -0x378 */ - sprintf(buf, "~/.sane/canon_pp-calibration-%s", + /* Form is ~/.sane/canon_pp-calibration-parport0 or -0x378 */ + i = strlen(default_weights_file_prefix) + + strlen(cs->params.port->name); + if ((cs->weights_file = malloc(i + 1)) == NULL) + return SANE_STATUS_NO_MEM; + sprintf(cs->weights_file, "%s%s", default_weights_file_prefix, cs->params.port->name); - cs->weights_file = strdup(buf); } /* Get the user's home dir if they used ~ */ if (cs->weights_file[0] == '~') { - if ((tmp = malloc(PATH_MAX)) == NULL) - return SANE_STATUS_NO_MEM; if ((myhome = getenv("HOME")) == NULL) { DBG(0,"fix_weights_file: FATAL: ~ used, but $HOME not" " set!\n"); - free(tmp); - tmp = NULL; return SANE_STATUS_INVAL; } - strncpy(tmp, myhome, PATH_MAX); - strncpy(tmp+strlen(tmp), (cs->weights_file)+1, - PATH_MAX-strlen(tmp)); + i = strlen(myhome) + strlen(&cs->weights_file[1]); + if ((tmp = malloc(i + 1)) == NULL) + return SANE_STATUS_NO_MEM; + sprintf(tmp, "%s%s", myhome, &cs->weights_file[1]); free(cs->weights_file); cs->weights_file = tmp; + tmp = NULL; } if ((f_stat = malloc(sizeof(*f_stat))) == NULL) |