Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
template: Added new approach
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Zronek authored and ZronekM committed Nov 17, 2019
1 parent eb9eb6b commit f3a5749
Show file tree
Hide file tree
Showing 19 changed files with 49 additions and 52 deletions.
3 changes: 2 additions & 1 deletion src/include/kdberrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ using KeySet = ckdb::KeySet;
do \
{ \
ELEKTRA_LOG ("Add Error %s", ELEKTRA_ERROR_OUT_OF_MEMORY); \
elektraSetErrorOUT_OF_MEMORY (key, __FILE__, ELEKTRA_STRINGIFY (__LINE__), ELEKTRA_STRINGIFY (ELEKTRA_MODULE_NAME)); \
elektraSetErrorOUT_OF_MEMORY (key, __FILE__, ELEKTRA_STRINGIFY (__LINE__), ELEKTRA_STRINGIFY (ELEKTRA_MODULE_NAME), \
"Memory allocation failed"); \
} while (0)

#define ELEKTRA_ADD_OUT_OF_MEMORY_WARNING(key, reason) \
Expand Down
8 changes: 2 additions & 6 deletions src/libs/elektra/errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ static void setError (Key * key, const char * code, const char * name, const cha
}

DEFINE_ERROR_AND_WARNING (RESOURCE)
DEFINE_ERROR_AND_WARNING (OUT_OF_MEMORY)
DEFINE_ERROR_AND_WARNING (INSTALLATION)
DEFINE_ERROR_AND_WARNING (INTERNAL)
DEFINE_ERROR_AND_WARNING (INTERFACE)
Expand All @@ -147,11 +148,6 @@ DEFINE_ERROR_AND_WARNING (CONFLICTING_STATE)
DEFINE_ERROR_AND_WARNING (VALIDATION_SYNTACTIC)
DEFINE_ERROR_AND_WARNING (VALIDATION_SEMANTIC)

void elektraSetErrorOUT_OF_MEMORY (Key * key, const char * file, const char * line, const char * module)
{
setError (key, ELEKTRA_ERROR_OUT_OF_MEMORY, ELEKTRA_ERROR_OUT_OF_MEMORY_NAME, file, line, module, "Out of memory");
}

KeySet * elektraErrorSpecification (void)
{
return ksNew (30, keyNew ("system/elektra/modules/error/specification", KEY_VALUE, "the specification of all error codes", KEY_END),
Expand Down Expand Up @@ -244,7 +240,7 @@ void elektraTriggerError (const char * nr, Key * parentKey, const char * message
}
if (strcmp (nr, ELEKTRA_ERROR_OUT_OF_MEMORY) == 0)
{
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parentKey, message);
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parentKey);
return;
}
if (strcmp (nr, ELEKTRA_ERROR_INSTALLATION) == 0)
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/augeas/augeas.c
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ static int saveTree (augeas * augeasHandle, KeySet * ks, const char * lensPath,

memoryerror:
elektraFree (keyArray);
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parentKey, "Unable to allocate memory while saving the augeas tree");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parentKey);
return -1;
}

Expand All @@ -432,7 +432,7 @@ int elektraAugeasOpen (Plugin * handle, Key * parentKey)

if (ret >= 0)
{
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parentKey, "Unable to allocate memory for a detailed augeas error message");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parentKey);
return -1;
}

Expand Down
10 changes: 5 additions & 5 deletions src/plugins/base64/base64.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static int unescape (Key * key, Key * parent)
char * unescaped = elektraStrDup (&strVal[1]);
if (!unescaped)
{
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parent, "Memory allocation failed");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parent);
return -1;
}
keySetString (key, unescaped);
Expand Down Expand Up @@ -112,7 +112,7 @@ static int decode (Key * key, Key * parent, bool metaMode)
else if (result == -2)
{
// Memory error
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parent, "Memory allocation failed");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parent);
return -1;
}

Expand All @@ -138,7 +138,7 @@ static int encode (Key * key, Key * parent, bool metaMode)
char * base64 = base64Encode (keyValue (key), (size_t) keyGetValueSize (key));
if (!base64)
{
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parent, "Memory allocation failed");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parent);
return -1;
}

Expand All @@ -152,7 +152,7 @@ static int encode (Key * key, Key * parent, bool metaMode)
char * newVal = elektraMalloc (newValLen);
if (!newVal)
{
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parent, "Memory allocation failed");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parent);
elektraFree (base64);
return -1;
}
Expand Down Expand Up @@ -192,7 +192,7 @@ static int escape (Key * key, Key * parent)
char * escapedVal = elektraMalloc (strValLen + 2);
if (!escapedVal)
{
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parent, "Memory allocation failed");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parent);
return -1;
}

Expand Down
8 changes: 4 additions & 4 deletions src/plugins/conditionals/conditionals.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ static CondResult evalCondition (const Key * curKey, const char * leftSide, Comp
}
if (elektraRealloc ((void **) &compareTo, (size_t) (endPos - rightSide)) < 0)
{
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parentKey, "Out of memory");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parentKey);
result = ERROR;
goto Cleanup;
}
Expand All @@ -226,7 +226,7 @@ static CondResult evalCondition (const Key * curKey, const char * leftSide, Comp

if (elektraRealloc ((void **) &lookupName, (size_t) len) < 0)
{
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parentKey, "Out of memory");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parentKey);
result = ERROR;
goto Cleanup;
}
Expand All @@ -251,7 +251,7 @@ static CondResult evalCondition (const Key * curKey, const char * leftSide, Comp
}
if (elektraRealloc ((void **) &compareTo, (size_t) keyGetValueSize (key)) < 0)
{
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parentKey, "Out of memory");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parentKey);
result = ERROR;
goto Cleanup;
}
Expand All @@ -267,7 +267,7 @@ static CondResult evalCondition (const Key * curKey, const char * leftSide, Comp

if (elektraRealloc ((void **) &lookupName, (size_t) len) < 0)
{
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parentKey, "Out of memory");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parentKey);
result = ERROR;
goto Cleanup;
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/crypto/botan_operations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static int getKeyIvForEncryption (KeySet * config, Key * errorKey, Key * masterK
}
if (!saltHexString)
{
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey, "Memory allocation failed");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey);
return -1;
}
keySetMeta (k, ELEKTRA_CRYPTO_META_SALT, saltHexString);
Expand Down
10 changes: 5 additions & 5 deletions src/plugins/crypto/gcrypt_operations.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static int getKeyIvForEncryption (KeySet * config, Key * errorKey, Key * masterK
}
if (!saltHexString)
{
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey, "Memory allocation failed");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey);
return -1;
}
keySetMeta (k, ELEKTRA_CRYPTO_META_SALT, saltHexString);
Expand Down Expand Up @@ -205,7 +205,7 @@ int elektraCryptoGcryHandleCreate (elektraCryptoHandle ** handle, KeySet * confi
memset (ivBuffer, 0, sizeof (ivBuffer));
keyDel (key);
keyDel (iv);
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey, "Memory allocation failed");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey);
return -1;
}

Expand Down Expand Up @@ -293,7 +293,7 @@ int elektraCryptoGcryEncrypt (elektraCryptoHandle * handle, Key * k, Key * error
kdb_octet_t * output = elektraMalloc (outputLen);
if (!output)
{
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey, "Memory allocation failed");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey);
elektraFree (salt);
return -1;
}
Expand Down Expand Up @@ -373,7 +373,7 @@ int elektraCryptoGcryDecrypt (elektraCryptoHandle * handle, Key * k, Key * error
kdb_octet_t * output = elektraMalloc (payloadLen);
if (!output)
{
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey, "Memory allocation failed");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey);
return -1;
}

Expand Down Expand Up @@ -446,7 +446,7 @@ char * elektraCryptoGcryCreateRandomString (Key * errorKey, const kdb_unsigned_s
}
if (!encoded)
{
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey, "Memory allocation failed");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey);
}
return encoded;
}
12 changes: 6 additions & 6 deletions src/plugins/crypto/gpg.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ static char * genGpgCandidate (Key * errorKey, char * dir, const char * file)
char * result = elektraMalloc (resultLen);
if (!result)
{
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey, "Memory allocation failed");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey);
return NULL;
}
snprintf (result, resultLen, "%s/%s", dir, file);
Expand Down Expand Up @@ -146,7 +146,7 @@ static int searchPathForBin (Key * errorKey, const char * bin, char ** result)
char * path = elektraMalloc (envPathLen);
if (!path)
{
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey, "Memory allocation failed");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey);
return -1;
}
memcpy (path, envPath, envPathLen);
Expand Down Expand Up @@ -196,7 +196,7 @@ int ELEKTRA_PLUGIN_FUNCTION (gpgGetBinary) (char ** gpgBin, KeySet * conf, Key *
*gpgBin = elektraMalloc (configPathLen + 1);
if (!(*gpgBin))
{
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey, "Memory allocation failed");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey);
return -1;
}
strncpy (*gpgBin, configPath, configPathLen);
Expand Down Expand Up @@ -237,7 +237,7 @@ int ELEKTRA_PLUGIN_FUNCTION (gpgGetBinary) (char ** gpgBin, KeySet * conf, Key *
*gpgBin = elektraStrDup (ELEKTRA_CRYPTO_DEFAULT_GPG2_BIN);
if (!(*gpgBin))
{
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey, "Memory allocation failed");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey);
return -1;
}
return 1;
Expand All @@ -249,7 +249,7 @@ int ELEKTRA_PLUGIN_FUNCTION (gpgGetBinary) (char ** gpgBin, KeySet * conf, Key *
*gpgBin = elektraStrDup (ELEKTRA_CRYPTO_DEFAULT_GPG1_BIN);
if (!(*gpgBin))
{
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey, "Memory allocation failed");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey);
return -1;
}
return 1;
Expand Down Expand Up @@ -645,7 +645,7 @@ int ELEKTRA_PLUGIN_FUNCTION (gpgCall) (KeySet * conf, Key * errorKey, Key * msgK
// estimated maximum output size = 2 * input (including headers, etc.)
if (msgKey && !(buffer = elektraMalloc (bufferSize)))
{
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey, "Memory allocation failed");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey);
closePipe (pipe_stdin);
closePipe (pipe_stdout);
closePipe (pipe_stderr);
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/crypto/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ int ELEKTRA_PLUGIN_FUNCTION (getSaltFromMetakey) (Key * errorKey, Key * k, kdb_o
}
else if (result == -2)
{
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey, "Memory allocation failed");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey);
return -1;
}
else if (result < -2)
Expand Down
10 changes: 5 additions & 5 deletions src/plugins/crypto/openssl_operations.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static int getKeyIvForEncryption (KeySet * config, Key * errorKey, Key * masterK
}
if (!saltHexString)
{
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey, "Memory allocation failed");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey);
return -1;
}
keySetMeta (k, ELEKTRA_CRYPTO_META_SALT, saltHexString);
Expand Down Expand Up @@ -223,7 +223,7 @@ int elektraCryptoOpenSSLHandleCreate (elektraCryptoHandle ** handle, KeySet * co
{
memset (keyBuffer, 0, sizeof (keyBuffer));
memset (ivBuffer, 0, sizeof (ivBuffer));
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey, "Memory allocation failed");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey);
return -1;
}

Expand Down Expand Up @@ -307,7 +307,7 @@ int elektraCryptoOpenSSLEncrypt (elektraCryptoHandle * handle, Key * k, Key * er
encrypted = BIO_new (BIO_s_mem ());
if (!encrypted)
{
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey, "Memory allocation failed");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey);
pthread_mutex_unlock (&mutex_ssl);
elektraFree (salt);
return -1;
Expand Down Expand Up @@ -433,7 +433,7 @@ int elektraCryptoOpenSSLDecrypt (elektraCryptoHandle * handle, Key * k, Key * er
BIO * decrypted = BIO_new (BIO_s_mem ());
if (!decrypted)
{
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey, "Memory allocation failed");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey);
pthread_mutex_unlock (&mutex_ssl);
return -1;
}
Expand Down Expand Up @@ -535,7 +535,7 @@ char * elektraCryptoOpenSSLCreateRandomString (Key * errorKey, const kdb_unsigne
}
if (!encoded)
{
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey, "Memory allocation failed");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey);
}
return encoded;
}
6 changes: 3 additions & 3 deletions src/plugins/fcrypt/fcrypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ static int fcryptEncrypt (KeySet * pluginConfig, Key * parentKey)
char * tmpFile = getTemporaryFileName (pluginConfig, keyString (parentKey), &tmpFileFd);
if (!tmpFile)
{
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parentKey, "Memory allocation failed");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parentKey);
return -1;
}

Expand Down Expand Up @@ -434,7 +434,7 @@ static int fcryptDecrypt (KeySet * pluginConfig, Key * parentKey, fcryptState *
char * tmpFile = getTemporaryFileName (pluginConfig, keyString (parentKey), &tmpFileFd);
if (!tmpFile)
{
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parentKey, "Memory allocation failed");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parentKey);
return -1;
}

Expand Down Expand Up @@ -513,7 +513,7 @@ int ELEKTRA_PLUGIN_FUNCTION (open) (Plugin * handle, KeySet * ks ELEKTRA_UNUSED,
fcryptState * s = elektraMalloc (sizeof (fcryptState));
if (!s)
{
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parentKey, "Memory allocation failed");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parentKey);
return -1;
}

Expand Down
10 changes: 5 additions & 5 deletions src/plugins/gpgme/gpgme.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ static gpgme_key_t * extractRecipientFromPluginConfig (KeySet * config, Key * er
{
if (!elektraGpgmeKeylistAdd (&list, key))
{
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey, "Memory allocation failed");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey);
elektraGpgmeKeylistFree (&list);
return NULL;
}
Expand Down Expand Up @@ -193,7 +193,7 @@ static gpgme_key_t * extractRecipientFromPluginConfig (KeySet * config, Key * er
{
if (!elektraGpgmeKeylistAdd (&list, key))
{
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey, "Memory allocation failed");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey);
elektraGpgmeKeylistFree (&list);
return NULL;
}
Expand All @@ -211,7 +211,7 @@ static gpgme_key_t * extractRecipientFromPluginConfig (KeySet * config, Key * er
gpgme_key_t * keyArray = elektraMalloc ((list.size + 1) * sizeof (gpgme_key_t));
if (!keyArray)
{
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey, "Memory allocation failed");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey);
elektraGpgmeKeylistFree (&list);
return NULL;
}
Expand Down Expand Up @@ -250,7 +250,7 @@ static int transferGpgmeDataToElektraKey (gpgme_data_t src, Key * dst, Key * err
buffer = (char *) elektraMalloc (ciphertextLen);
if (!buffer)
{
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey, "Memory allocation failed");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey);
returnValue = -1; // failure
goto cleanup;
}
Expand Down Expand Up @@ -438,7 +438,7 @@ static int gpgEncrypt (Plugin * handle, KeySet * data, Key * errorKey)
}
else
{
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey, "Memory allocation failed");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey);
}
gpgme_data_release (ciphertext);
gpgme_data_release (input);
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/ini/ini.c
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ int elektraIniGet (Plugin * handle, KeySet * returned, Key * parentKey)
ELEKTRA_SET_RESOURCE_ERROR (parentKey, "Unable to open the ini file");
break;
case -2:
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parentKey, "Memory allocation error while reading the ini file");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parentKey);
break;
default:
ELEKTRA_SET_VALIDATION_SYNTACTIC_ERRORF (parentKey, "Could not parse ini file %s. First error at line %d",
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/ipaddr/ipaddr.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ static int validateKey (Key * key, Key * parentKey)
}
else if (rc == -1)
{
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parentKey, "Out of memory");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (parentKey);
rc = 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/jni/jni.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ int elektraJniOpen (Plugin * handle, Key * errorKey)
ELEKTRA_SET_INSTALLATION_ERROR (errorKey, "Cannot create Java VM: JNI version error");
return -1;
case JNI_ENOMEM:
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey, "Cannot create Java VM: Not enough memory");
ELEKTRA_SET_OUT_OF_MEMORY_ERROR (errorKey);
return -1;
case JNI_EEXIST:
ELEKTRA_SET_RESOURCE_ERROR (errorKey, "Cannot create Java VM: VM already created");
Expand Down
Loading

0 comments on commit f3a5749

Please sign in to comment.