From ec854d5774cee9ec1039b4348824682a9003365d Mon Sep 17 00:00:00 2001 From: Jordan Filteau Date: Sun, 13 Aug 2023 00:23:33 -0500 Subject: [PATCH 1/5] configmgr error message improvements Signed-off-by: Jordan Filteau --- c/configmgr.c | 15 ++++++++++----- c/embeddedjs.c | 1 - c/yaml2json.c | 46 ++++++++++++++++++++++++++++++---------------- 3 files changed, 40 insertions(+), 22 deletions(-) diff --git a/c/configmgr.c b/c/configmgr.c index 0526ab2a9..41394ca2c 100644 --- a/c/configmgr.c +++ b/c/configmgr.c @@ -673,6 +673,9 @@ static Json *readYamlIntoJson(ConfigManager *mgr, char *filename, bool allowMiss trace(mgr,DEBUG,"before read YAML mgr=0x%p file=%s\n",mgr,filename); bool wasMissing = false; yaml_document_t *doc = readYAML2(filename,errorBuffer,YAML_ERROR_MAX,&wasMissing); + /* + * errorBuffer is ebcdic. + */ trace(mgr,DEBUG,"yaml doc at 0x%p, allowMissing=%d wasMissing=%d\n",doc,allowMissingFile,wasMissing); if (doc){ if (mgr->traceLevel >= 1){ @@ -682,11 +685,13 @@ static Json *readYamlIntoJson(ConfigManager *mgr, char *filename, bool allowMiss } else if (allowMissingFile && wasMissing){ return NULL; } else{ - trace(mgr,INFO,"WARNING, yaml read failed, errorBuffer='%s'\n",errorBuffer); -#ifdef __ZOWE_OS_ZOS - a2e(errorBuffer,YAML_ERROR_MAX); +#ifndef __ZOWE_OS_ZOS + /* + * Let's convert to ascii if we aren't on z/OS. + */ + e2a(errorBuffer,YAML_ERROR_MAX); #endif - trace(mgr,INFO,"WARNING, yaml read failed, errorBuffer='%s'\n",errorBuffer); + trace(mgr,INFO,"Couldn't read '%s', because, %s\n",filename,errorBuffer); return NULL; } } @@ -1729,7 +1734,7 @@ static int simpleMain(int argc, char **argv){ } int loadStatus = cfgLoadConfiguration(mgr,configName); if (loadStatus){ - trace(mgr,INFO,"Failed to load configuration, element may be bad, or less likey a bad merge\n"); + trace(mgr,INFO,"Failed to load configuration, element may be bad, or less likely a bad merge.\n"); return loadStatus; } trace(mgr,DEBUG,"configuration parms are loaded\n"); diff --git a/c/embeddedjs.c b/c/embeddedjs.c index 83d7d76a2..aad75a32d 100644 --- a/c/embeddedjs.c +++ b/c/embeddedjs.c @@ -1890,7 +1890,6 @@ Json *evaluateJsonTemplates(EmbeddedJS *ejs, ShortLivedHeap *slh, Json *json){ visitJSON(json,NULL,NULL,-1,evaluationVisitor,&evalContext); return json; } else { - printf("top json is not an object\n"); return NULL; } } diff --git a/c/yaml2json.c b/c/yaml2json.c index dc343bff7..5b0ece248 100644 --- a/c/yaml2json.c +++ b/c/yaml2json.c @@ -123,15 +123,23 @@ static int yamlReadHandler(void *data, unsigned char *buffer, size_t size, size_ } static void decodeParserError(yaml_parser_t *parser, char *errorBuf, size_t errorBufSize) { + size_t problemLen = strlen(parser->problem); + char problemNative[problemLen + 1]; + snprintf (problemNative, problemLen + 1, "%s", parser->problem); + convertToNative(problemNative, problemLen); + char *nativeContext = NULL; + if (parser->context) { + size_t contextLen = strlen(parser->context); + char contextNative[contextLen + 1]; + snprintf(contextNative, contextLen + 1, "%s", parser->context); + convertToNative(contextNative, contextLen); + nativeContext = contextNative; + } switch (parser->error) { case YAML_MEMORY_ERROR: snprintf(errorBuf, errorBufSize, "YAML memory error: not enough memory for parsing"); break; case YAML_READER_ERROR: { - size_t problemLen = strlen(parser->problem); - char problemNative[problemLen + 1]; - snprintf (problemNative, problemLen + 1, "%s", parser->problem); - convertToNative(problemNative, problemLen); if (parser->problem_value != -1) { snprintf(errorBuf, errorBufSize, "YAML reader error: %s: #%X at %ld", problemNative, parser->problem_value, (long)parser->problem_offset); } else { @@ -141,27 +149,33 @@ static void decodeParserError(yaml_parser_t *parser, char *errorBuf, size_t erro } case YAML_SCANNER_ERROR: if (parser->context) { - snprintf(errorBuf, errorBufSize, "YAML scanner error: %s at line %d, column %d" - "%s at line %d, column %d\n", parser->context, + snprintf(errorBuf, errorBufSize, + "%s at line %d, column %d; " + "%s at line %d, column %d.", + nativeContext, (int)parser->context_mark.line+1, (int)parser->context_mark.column+1, - parser->problem, (int)parser->problem_mark.line+1, + problemNative, (int)parser->problem_mark.line+1, (int)parser->problem_mark.column+1); } else { - snprintf(errorBuf, errorBufSize, "YAML scanner error: %s at line %d, column %d", - parser->problem, (int)parser->problem_mark.line+1, + snprintf(errorBuf, errorBufSize, + "%s at line %d, column %d.", + problemNative, (int)parser->problem_mark.line+1, (int)parser->problem_mark.column+1); } break; case YAML_PARSER_ERROR: if (parser->context) { - snprintf(errorBuf, errorBufSize, "YAML parser error: %s at line %d, column %d\n" - "%s at line %d, column %d", parser->context, - (int)parser->context_mark.line+1, (int)parser->context_mark.column+1, - parser->problem, (int)parser->problem_mark.line+1, - (int)parser->problem_mark.column+1); + snprintf(errorBuf, errorBufSize, + "%s at line %d, column %d; " + "%s at line %d, column %d.", + nativeContext, + (int)parser->context_mark.line+1, (int)parser->context_mark.column+1, + problemNative, (int)parser->problem_mark.line+1, + (int)parser->problem_mark.column+1); } else { - snprintf(errorBuf, errorBufSize, "YAML parser error: %s at line %d, column %d", - parser->problem, (int)parser->problem_mark.line+1, + snprintf(errorBuf, errorBufSize, + "%s at line %d, column %d.", + problemNative, (int)parser->problem_mark.line+1, (int)parser->problem_mark.column+1); } break; From b19e743b8b109ff4bf3d94d7fd873540434bf10e Mon Sep 17 00:00:00 2001 From: Jordan Filteau Date: Sun, 13 Aug 2023 14:46:11 -0500 Subject: [PATCH 2/5] better formatting for message; message id Signed-off-by: Jordan Filteau --- c/configmgr.c | 45 ++++++++++++++++++++++++++++++++++++++++++--- c/yaml2json.c | 24 ++++++++++++++++-------- 2 files changed, 58 insertions(+), 11 deletions(-) diff --git a/c/configmgr.c b/c/configmgr.c index 41394ca2c..fc58044ab 100644 --- a/c/configmgr.c +++ b/c/configmgr.c @@ -668,6 +668,27 @@ int cfgSetConfigPath(ConfigManager *mgr, const char *configName, char *configPat #define YAML_ERROR_MAX 1024 #define MAX_PDS_NAME 1000 /* very generous */ +static void replaceFileNameInString(char *string, char *replaceWith, int all) { + + char buffer[YAML_ERROR_MAX+USS_MAX_PATH_LENGTH+1] = {0}; + char *index; + char *start = string; + + index = strstr(string, "&name"); + + while (index != NULL) { + strncat(buffer, start, index - start); + strcat(buffer, replaceWith); + start = index + strlen("&name"); + if (!all) { + break; + } + index = strstr(start, "&name"); + } + strcat(buffer, start); + strcpy(string, buffer); +} + static Json *readYamlIntoJson(ConfigManager *mgr, char *filename, bool allowMissingFile){ char errorBuffer[YAML_ERROR_MAX]; trace(mgr,DEBUG,"before read YAML mgr=0x%p file=%s\n",mgr,filename); @@ -675,6 +696,9 @@ static Json *readYamlIntoJson(ConfigManager *mgr, char *filename, bool allowMiss yaml_document_t *doc = readYAML2(filename,errorBuffer,YAML_ERROR_MAX,&wasMissing); /* * errorBuffer is ebcdic. + * + * parser explanation was passed into 'convertToNative()' to go from + * ascii to ebcdic. */ trace(mgr,DEBUG,"yaml doc at 0x%p, allowMissing=%d wasMissing=%d\n",doc,allowMissingFile,wasMissing); if (doc){ @@ -687,11 +711,26 @@ static Json *readYamlIntoJson(ConfigManager *mgr, char *filename, bool allowMiss } else{ #ifndef __ZOWE_OS_ZOS /* - * Let's convert to ascii if we aren't on z/OS. + * Let's convert to ascii if we aren't on z/OS? */ e2a(errorBuffer,YAML_ERROR_MAX); #endif - trace(mgr,INFO,"Couldn't read '%s', because, %s\n",filename,errorBuffer); + /* + * We should get the absolute path to the file name because the 'filename' + * variable is a relative path. It will make debugging more difficult. + * + * msg is a buffer that can take the max path length and error length. We'll replace &name + * here for better user experience. + */ + char msg[YAML_ERROR_MAX + USS_MAX_PATH_LENGTH+1] = {0}; + strcpy(msg,errorBuffer); + char fileOrPath[USS_MAX_PATH_LENGTH+1] = {0}; + if (!realpath(filename,fileOrPath)) { + trace(mgr,DEBUG,"realpath(): ERRNO=%d\n",errno); /* i hope not */ + strcpy(fileOrPath,filename); + } + replaceFileNameInString(msg,fileOrPath,1); + trace(mgr,INFO,"%s - %s\n","ZWEL0318E",msg); return NULL; } } @@ -1734,7 +1773,7 @@ static int simpleMain(int argc, char **argv){ } int loadStatus = cfgLoadConfiguration(mgr,configName); if (loadStatus){ - trace(mgr,INFO,"Failed to load configuration, element may be bad, or less likely a bad merge.\n"); + trace(mgr,INFO,"%s - Failed to load configuration, element may be bad, or less likely a bad merge.\n", "ZWEL0319E"); return loadStatus; } trace(mgr,DEBUG,"configuration parms are loaded\n"); diff --git a/c/yaml2json.c b/c/yaml2json.c index 5b0ece248..e5fccaefc 100644 --- a/c/yaml2json.c +++ b/c/yaml2json.c @@ -135,22 +135,30 @@ static void decodeParserError(yaml_parser_t *parser, char *errorBuf, size_t erro convertToNative(contextNative, contextLen); nativeContext = contextNative; } + /* + * We aren't sending back the parser far enough to determine the type of error. We + * want to know the file in question, so we'll rely on the processor of this errorBuffer + * to use replaceString("&name", name). + */ switch (parser->error) { case YAML_MEMORY_ERROR: - snprintf(errorBuf, errorBufSize, "YAML memory error: not enough memory for parsing"); + snprintf(errorBuf, errorBufSize, "Couldn't allocate enough memory to process file '&name'."); break; case YAML_READER_ERROR: { if (parser->problem_value != -1) { - snprintf(errorBuf, errorBufSize, "YAML reader error: %s: #%X at %ld", problemNative, parser->problem_value, (long)parser->problem_offset); + snprintf(errorBuf, + errorBufSize, + "Couldn't read file '&name': %s, #%x at %ld.", + problemNative, parser->problem_value, (long)parser->problem_offset); } else { - snprintf(errorBuf, errorBufSize, "YAML reader error: %s at %ld", problemNative, (long)parser->problem_offset); + snprintf(errorBuf, errorBufSize, "Couldn't read file '&name': %s at %ld.", problemNative, (long)parser->problem_offset); } break; } case YAML_SCANNER_ERROR: if (parser->context) { snprintf(errorBuf, errorBufSize, - "%s at line %d, column %d; " + "Couldn't scan file '&name': %s at line %d, column %d, " "%s at line %d, column %d.", nativeContext, (int)parser->context_mark.line+1, (int)parser->context_mark.column+1, @@ -158,7 +166,7 @@ static void decodeParserError(yaml_parser_t *parser, char *errorBuf, size_t erro (int)parser->problem_mark.column+1); } else { snprintf(errorBuf, errorBufSize, - "%s at line %d, column %d.", + "Couldn't scan file '&name': %s at line %d, column %d.", problemNative, (int)parser->problem_mark.line+1, (int)parser->problem_mark.column+1); } @@ -166,7 +174,7 @@ static void decodeParserError(yaml_parser_t *parser, char *errorBuf, size_t erro case YAML_PARSER_ERROR: if (parser->context) { snprintf(errorBuf, errorBufSize, - "%s at line %d, column %d; " + "Couldn't parse file '&name': %s at line %d, column %d, " "%s at line %d, column %d.", nativeContext, (int)parser->context_mark.line+1, (int)parser->context_mark.column+1, @@ -174,13 +182,13 @@ static void decodeParserError(yaml_parser_t *parser, char *errorBuf, size_t erro (int)parser->problem_mark.column+1); } else { snprintf(errorBuf, errorBufSize, - "%s at line %d, column %d.", + "Couldn't parse file '&name': %s at line %d, column %d.", problemNative, (int)parser->problem_mark.line+1, (int)parser->problem_mark.column+1); } break; default: - snprintf(errorBuf, errorBufSize, "YAML parser: unknown error"); + snprintf(errorBuf, errorBufSize, "Couldn't process file '&name' because of an unknown error type '%d'.", parser->error); } } From af876891366202a97f6862ece0e3503172a05d94 Mon Sep 17 00:00:00 2001 From: Jordan Filteau Date: Tue, 29 Aug 2023 17:01:56 -0400 Subject: [PATCH 3/5] removing complex logic of string replacing a 'name' placeholder in favor of just passing the filename; fixing dangling pointer issue; fixing whitespace problems. Signed-off-by: Jordan Filteau --- c/configmgr.c | 60 +++++++++++++++++---------------------------- c/yaml2json.c | 67 ++++++++++++++++++++++++++++++--------------------- 2 files changed, 61 insertions(+), 66 deletions(-) diff --git a/c/configmgr.c b/c/configmgr.c index fc58044ab..0c6380238 100644 --- a/c/configmgr.c +++ b/c/configmgr.c @@ -668,27 +668,6 @@ int cfgSetConfigPath(ConfigManager *mgr, const char *configName, char *configPat #define YAML_ERROR_MAX 1024 #define MAX_PDS_NAME 1000 /* very generous */ -static void replaceFileNameInString(char *string, char *replaceWith, int all) { - - char buffer[YAML_ERROR_MAX+USS_MAX_PATH_LENGTH+1] = {0}; - char *index; - char *start = string; - - index = strstr(string, "&name"); - - while (index != NULL) { - strncat(buffer, start, index - start); - strcat(buffer, replaceWith); - start = index + strlen("&name"); - if (!all) { - break; - } - index = strstr(start, "&name"); - } - strcat(buffer, start); - strcpy(string, buffer); -} - static Json *readYamlIntoJson(ConfigManager *mgr, char *filename, bool allowMissingFile){ char errorBuffer[YAML_ERROR_MAX]; trace(mgr,DEBUG,"before read YAML mgr=0x%p file=%s\n",mgr,filename); @@ -713,28 +692,27 @@ static Json *readYamlIntoJson(ConfigManager *mgr, char *filename, bool allowMiss /* * Let's convert to ascii if we aren't on z/OS? */ - e2a(errorBuffer,YAML_ERROR_MAX); + e2a(errorBuffer,sizeof(errorBuffer)); #endif - /* - * We should get the absolute path to the file name because the 'filename' - * variable is a relative path. It will make debugging more difficult. - * - * msg is a buffer that can take the max path length and error length. We'll replace &name - * here for better user experience. - */ - char msg[YAML_ERROR_MAX + USS_MAX_PATH_LENGTH+1] = {0}; - strcpy(msg,errorBuffer); - char fileOrPath[USS_MAX_PATH_LENGTH+1] = {0}; - if (!realpath(filename,fileOrPath)) { - trace(mgr,DEBUG,"realpath(): ERRNO=%d\n",errno); /* i hope not */ - strcpy(fileOrPath,filename); - } - replaceFileNameInString(msg,fileOrPath,1); trace(mgr,INFO,"%s - %s\n","ZWEL0318E",msg); return NULL; } } +static char *getAbsolutePathOrKeepRelativePath(const char *filename, ShortLivedHeap *slh) { + + char *fileOrPath = SLHAlloc(slh, USS_MAX_PATH_LENGTH+1); + + if (fileOrPath) { + if (!realpath(filename, fileOrPath)) { + trace(mgr,DEBUG,"Couldn't get absolute path for '%s'. errno=%d\n", filename, errno); + strcpy(fileOrPath, filename); + } + } + + return fileOrPath; +} + static Json *readJson(ConfigManager *mgr, CFGConfig *config, ConfigPathElement *pathElement, bool *nullAllowedPtr){ *nullAllowedPtr = false; if (pathElement == NULL){ @@ -746,7 +724,13 @@ static Json *readJson(ConfigManager *mgr, CFGConfig *config, ConfigPathElement * return NULL; } if (pathElement->flags & CONFIG_PATH_OMVS_FILE){ - return readYamlIntoJson(mgr,pathElement->data,false); + /* + * This probably won't ever return null because we'd have to fail an allocation of 1024 bytes... + * Just in case, we will default to pathElement->data if 'absolutePath' comes back as null because + * it should be the same thing anyways. + */ + char *absolutePath = getAbsolutePathOrKeepRelativePath(pathElement->data,mgr->slh); + return readYamlIntoJson(mgr,absolutePath ? absolutePath : pathElement->data,false); } else if (pathElement->flags & CONFIG_PATH_MVS_PARMLIB){ char pdsMemberSpec[MAX_PDS_NAME]; trace(mgr,DEBUG,"pathElement=0x%p config=0x%p\n",pathElement,config); diff --git a/c/yaml2json.c b/c/yaml2json.c index e5fccaefc..cf7b147c2 100644 --- a/c/yaml2json.c +++ b/c/yaml2json.c @@ -122,73 +122,84 @@ static int yamlReadHandler(void *data, unsigned char *buffer, size_t size, size_ return rc; } -static void decodeParserError(yaml_parser_t *parser, char *errorBuf, size_t errorBufSize) { +static void decodeParserError(yaml_parser_t *parser, char *errorBuf, size_t errorBufSize, const char *filename) { + /* + * Convert diagnostics (problem and context) from ascii to ebcdic so that the error buffer that is returned from this function + * is in native codepage. + */ size_t problemLen = strlen(parser->problem); - char problemNative[problemLen + 1]; - snprintf (problemNative, problemLen + 1, "%s", parser->problem); - convertToNative(problemNative, problemLen); + char *problemNative = safeMalloc(problemLen + 1, "parser problem"); + if (problemNative) { + memset(problemNative, 0, problemLen + 1); + strcpy(problemNative, parser->problem); + convertToNative(problemNative, problemLen); + } char *nativeContext = NULL; if (parser->context) { size_t contextLen = strlen(parser->context); - char contextNative[contextLen + 1]; - snprintf(contextNative, contextLen + 1, "%s", parser->context); - convertToNative(contextNative, contextLen); - nativeContext = contextNative; + nativeContext = safeMalloc(contextLen + 1, "parser context"); + if (nativeContext) { + memset(nativeContext, 0, contextLen + 1); + strcpy(nativeContext, parser->context); + convertToNative(contextNative, contextLen); + } } - /* - * We aren't sending back the parser far enough to determine the type of error. We - * want to know the file in question, so we'll rely on the processor of this errorBuffer - * to use replaceString("&name", name). - */ switch (parser->error) { case YAML_MEMORY_ERROR: - snprintf(errorBuf, errorBufSize, "Couldn't allocate enough memory to process file '&name'."); + snprintf(errorBuf, errorBufSize, "Couldn't allocate enough memory to process file '%s'.", filename); break; case YAML_READER_ERROR: { if (parser->problem_value != -1) { snprintf(errorBuf, errorBufSize, - "Couldn't read file '&name': %s, #%x at %ld.", - problemNative, parser->problem_value, (long)parser->problem_offset); + "Couldn't read file '%s': %s, #%x at %ld.", + filename, problemNative, parser->problem_value, (long)parser->problem_offset); } else { - snprintf(errorBuf, errorBufSize, "Couldn't read file '&name': %s at %ld.", problemNative, (long)parser->problem_offset); + snprintf(errorBuf, errorBufSize, "Couldn't read file %s: %s at %ld.", filename, problemNative, (long)parser->problem_offset); } break; } case YAML_SCANNER_ERROR: if (parser->context) { snprintf(errorBuf, errorBufSize, - "Couldn't scan file '&name': %s at line %d, column %d, " + "Couldn't scan file '%s': %s at line %d, column %d, " "%s at line %d, column %d.", - nativeContext, + filename, nativeContext, (int)parser->context_mark.line+1, (int)parser->context_mark.column+1, problemNative, (int)parser->problem_mark.line+1, (int)parser->problem_mark.column+1); } else { snprintf(errorBuf, errorBufSize, - "Couldn't scan file '&name': %s at line %d, column %d.", - problemNative, (int)parser->problem_mark.line+1, - (int)parser->problem_mark.column+1); + "Couldn't scan file '%s': %s at line %d, column %d.", + filename, problemNative, (int)parser->problem_mark.line+1, + (int)parser->problem_mark.column+1); } break; case YAML_PARSER_ERROR: if (parser->context) { snprintf(errorBuf, errorBufSize, - "Couldn't parse file '&name': %s at line %d, column %d, " + "Couldn't parse file '%s': %s at line %d, column %d, " "%s at line %d, column %d.", - nativeContext, + filename, nativeContext, (int)parser->context_mark.line+1, (int)parser->context_mark.column+1, problemNative, (int)parser->problem_mark.line+1, (int)parser->problem_mark.column+1); } else { snprintf(errorBuf, errorBufSize, - "Couldn't parse file '&name': %s at line %d, column %d.", - problemNative, (int)parser->problem_mark.line+1, + "Couldn't parse file '%s': %s at line %d, column %d.", + filename, problemNative, (int)parser->problem_mark.line+1, (int)parser->problem_mark.column+1); } break; default: - snprintf(errorBuf, errorBufSize, "Couldn't process file '&name' because of an unknown error type '%d'.", parser->error); + snprintf(errorBuf, errorBufSize, "Couldn't process file '%s' because of an unknown error type '%d'.", filename, parser->error); + } + /* + * We've already copied the information into the errorBuffer so we can free these now. + */ + safeFree(problemNative, problemLen); + if (contextNative) { + safeFree(contextNative, contextLen); } } @@ -215,7 +226,7 @@ yaml_document_t *readYAML2(const char *filename, char *errorBuf, size_t errorBuf } yaml_parser_set_input(&parser, yamlReadHandler, file); if (!yaml_parser_load(&parser, document)) { - decodeParserError(&parser, errorBuf, errorBufSize); + decodeParserError(&parser, errorBuf, errorBufSize, filename); break; } if (!yaml_document_get_root_node(document)){ From e5d0628a53c8fa21c956ef14c1e910c9b58d4499 Mon Sep 17 00:00:00 2001 From: Jordan Filteau Date: Tue, 29 Aug 2023 16:26:07 -0500 Subject: [PATCH 4/5] fixing compiler errors introduced by recent changes Signed-off-by: Jordan Filteau --- c/configmgr.c | 11 ++++++----- c/yaml2json.c | 17 +++++++++-------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/c/configmgr.c b/c/configmgr.c index 0c6380238..512ec30fa 100644 --- a/c/configmgr.c +++ b/c/configmgr.c @@ -694,18 +694,19 @@ static Json *readYamlIntoJson(ConfigManager *mgr, char *filename, bool allowMiss */ e2a(errorBuffer,sizeof(errorBuffer)); #endif - trace(mgr,INFO,"%s - %s\n","ZWEL0318E",msg); + trace(mgr,INFO,"%s - %s\n","ZWEL0318E",errorBuffer); return NULL; } } -static char *getAbsolutePathOrKeepRelativePath(const char *filename, ShortLivedHeap *slh) { +static char *getAbsolutePathOrKeepRelativePath(const char *filename, ConfigManager *mgr) { - char *fileOrPath = SLHAlloc(slh, USS_MAX_PATH_LENGTH+1); + char *fileOrPath = SLHAlloc(mgr->slh, USS_MAX_PATH_LENGTH+1); if (fileOrPath) { + memset(fileOrPath, 0, USS_MAX_PATH_LENGTH+1); if (!realpath(filename, fileOrPath)) { - trace(mgr,DEBUG,"Couldn't get absolute path for '%s'. errno=%d\n", filename, errno); + trace(mgr, DEBUG, "Couldn't get absolute path for '%s'. errno=%d\n", filename, errno); strcpy(fileOrPath, filename); } } @@ -729,7 +730,7 @@ static Json *readJson(ConfigManager *mgr, CFGConfig *config, ConfigPathElement * * Just in case, we will default to pathElement->data if 'absolutePath' comes back as null because * it should be the same thing anyways. */ - char *absolutePath = getAbsolutePathOrKeepRelativePath(pathElement->data,mgr->slh); + char *absolutePath = getAbsolutePathOrKeepRelativePath(pathElement->data,mgr); return readYamlIntoJson(mgr,absolutePath ? absolutePath : pathElement->data,false); } else if (pathElement->flags & CONFIG_PATH_MVS_PARMLIB){ char pdsMemberSpec[MAX_PDS_NAME]; diff --git a/c/yaml2json.c b/c/yaml2json.c index cf7b147c2..a5f9c2ad3 100644 --- a/c/yaml2json.c +++ b/c/yaml2json.c @@ -134,13 +134,14 @@ static void decodeParserError(yaml_parser_t *parser, char *errorBuf, size_t erro strcpy(problemNative, parser->problem); convertToNative(problemNative, problemLen); } - char *nativeContext = NULL; + size_t contextLen = 0; + char *contextNative = NULL; if (parser->context) { - size_t contextLen = strlen(parser->context); - nativeContext = safeMalloc(contextLen + 1, "parser context"); - if (nativeContext) { - memset(nativeContext, 0, contextLen + 1); - strcpy(nativeContext, parser->context); + contextLen = strlen(parser->context); + contextNative = safeMalloc(contextLen + 1, "parser context"); + if (contextNative) { + memset(contextNative, 0, contextLen + 1); + strcpy(contextNative, parser->context); convertToNative(contextNative, contextLen); } } @@ -164,7 +165,7 @@ static void decodeParserError(yaml_parser_t *parser, char *errorBuf, size_t erro snprintf(errorBuf, errorBufSize, "Couldn't scan file '%s': %s at line %d, column %d, " "%s at line %d, column %d.", - filename, nativeContext, + filename, contextNative, (int)parser->context_mark.line+1, (int)parser->context_mark.column+1, problemNative, (int)parser->problem_mark.line+1, (int)parser->problem_mark.column+1); @@ -180,7 +181,7 @@ static void decodeParserError(yaml_parser_t *parser, char *errorBuf, size_t erro snprintf(errorBuf, errorBufSize, "Couldn't parse file '%s': %s at line %d, column %d, " "%s at line %d, column %d.", - filename, nativeContext, + filename, contextNative, (int)parser->context_mark.line+1, (int)parser->context_mark.column+1, problemNative, (int)parser->problem_mark.line+1, (int)parser->problem_mark.column+1); From d4821d3d45ba2b372981449f9d61d0d8cce761c7 Mon Sep 17 00:00:00 2001 From: Jordan Filteau Date: Wed, 30 Aug 2023 15:10:19 -0500 Subject: [PATCH 5/5] fixing not needed casts. Signed-off-by: Jordan Filteau --- c/yaml2json.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/c/yaml2json.c b/c/yaml2json.c index cf7b147c2..1e643d2ef 100644 --- a/c/yaml2json.c +++ b/c/yaml2json.c @@ -152,10 +152,10 @@ static void decodeParserError(yaml_parser_t *parser, char *errorBuf, size_t erro if (parser->problem_value != -1) { snprintf(errorBuf, errorBufSize, - "Couldn't read file '%s': %s, #%x at %ld.", - filename, problemNative, parser->problem_value, (long)parser->problem_offset); + "Couldn't read file '%s': %s, #%x at %zu.", + filename, problemNative, parser->problem_value, parser->problem_offset); } else { - snprintf(errorBuf, errorBufSize, "Couldn't read file %s: %s at %ld.", filename, problemNative, (long)parser->problem_offset); + snprintf(errorBuf, errorBufSize, "Couldn't read file %s: %s at %zu.", filename, problemNative, parser->problem_offset); } break; }