From 3db25e7e3bb38c8ea4e6f9012d8d8a3a63eeda39 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Sun, 23 Nov 2014 14:01:10 -0500 Subject: [PATCH] Some more attempts at being better at memory handling + remove useless and untested cygwin stuff. --- MasterPassword/C/mpw.c | 12 ------------ MasterPassword/C/types.c | 23 +++++++++++++---------- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/MasterPassword/C/mpw.c b/MasterPassword/C/mpw.c index 73ce75f4..f6fd7ff9 100644 --- a/MasterPassword/C/mpw.c +++ b/MasterPassword/C/mpw.c @@ -6,8 +6,6 @@ #include #if defined(__linux__) #include -#elif defined(__CYGWIN__) -#include #else #include #endif @@ -72,21 +70,11 @@ void usage() { char *homedir(const char *filename) { char *homedir = NULL; -#if defined(__CYGWIN__) - homedir = getenv("USERPROFILE"); - if (!homedir) { - const char *homeDrive = getenv("HOMEDRIVE"); - const char *homePath = getenv("HOMEPATH"); - homedir = char[strlen(homeDrive) + strlen(homePath) + 1]; - sprintf(homedir, "%s/%s", homeDrive, homePath); - } -#else struct passwd* passwd = getpwuid(getuid()); if (passwd) homedir = passwd->pw_dir; if (!homedir) homedir = getenv("HOME"); -#endif if (!homedir) homedir = getcwd(NULL, 0); diff --git a/MasterPassword/C/types.c b/MasterPassword/C/types.c index acebe35f..3997782f 100644 --- a/MasterPassword/C/types.c +++ b/MasterPassword/C/types.c @@ -198,11 +198,15 @@ const char *Hex(const void *buf, size_t length) { int putvari; char *putvarc = NULL; +bool istermsetup = false; static void initputvar() { if (putvarc) free(putvarc); - putvari=0; putvarc=(char *)calloc(256, sizeof(char)); + putvari=0; + + if (!istermsetup) + istermsetup = (OK == setupterm(NULL, STDERR_FILENO, NULL)); } static int putvar(int c) { putvarc[putvari++]=c; @@ -227,7 +231,6 @@ const char *Identicon(const char *userName, const char *masterPassword) { uint8_t colorIdentifier = identiconSeed[4] % 7 + 1; char *colorString, *resetString; if (useColor) { - setupterm(NULL, STDERR_FILENO, NULL); initputvar(); tputs(tparm(tgetstr("AF", NULL), colorIdentifier), 1, putvar); colorString = calloc(strlen(putvarc) + 1, sizeof(char)); @@ -240,14 +243,14 @@ const char *Identicon(const char *userName, const char *masterPassword) { resetString = calloc(1, sizeof(char)); } - char *identicon = (char *)calloc(20, sizeof(char)); - sprintf(identicon, "%s%s%s%s%s%s", - colorString, - leftArm[identiconSeed[0] % (sizeof(leftArm) / sizeof(leftArm[0]))], - body[identiconSeed[1] % (sizeof(body) / sizeof(body[0]))], - rightArm[identiconSeed[2] % (sizeof(rightArm) / sizeof(rightArm[0]))], - accessory[identiconSeed[3] % (sizeof(accessory) / sizeof(accessory[0]))], - resetString); + char *identicon = (char *)calloc(256, sizeof(char)); + snprintf(identicon, 256, "%s%s%s%s%s%s", + colorString, + leftArm[identiconSeed[0] % (sizeof(leftArm) / sizeof(leftArm[0]))], + body[identiconSeed[1] % (sizeof(body) / sizeof(body[0]))], + rightArm[identiconSeed[2] % (sizeof(rightArm) / sizeof(rightArm[0]))], + accessory[identiconSeed[3] % (sizeof(accessory) / sizeof(accessory[0]))], + resetString); free(colorString); free(resetString);