Я получаю ошибку сегментации при запуске моей программы. Я пробовал отладку с помощью инструмента valgrind. Программа запускается так:
errors_e read_limits_epic_data_from_db()
{
char sql[MAX_SIZE] = {}
generate_sql_query_for_epic_cache(sql, db_sys_params)
}
generate_sql_query_for_epic_cache выглядит так:
char * generate_sql_query_for_epic_cache(char *buffer, db_sys_params_t *db_sys_params)
{
char *limit_table_name = NULL;
char *sql_frmt = "select * from %s where Key %s '%s'";
char key_epic[MAX_SIZE];
char *condition = " = ";
if (db_sys_params->shelf == DS14) {
condition = " like ";
}
if (db_sys_params->hw_vendor == LE) {
limit_table_name = "CSI_EPIC_LE_LIMITS";
}
else if(db_sys_params->hw_vendor == FU) {
limit_table_name = "CSI_EPIC_FU_LIMITS";
}
else {
limit_table_name = "CSI_EPIC_LIMITS";
}
get_epic_key(key_epic,db_sys_params);
snprintf(buffer, MAX_SIZE, sql_frmt, limit_table_name, condition, key_epic);
return buffer;
}
get_epic_key выглядит так:
char * get_epic_key(char *buffer, db_sys_params_t *db_sys_params)
{
char *frmt = "%s%s%s%s%s";
char *mode = get_epic_mode_name_equivalent_to_csi(db_sys_params);
char *version = get_on_version_equivalent_to_csi(db_sys_params);
char *shelf = get_shelf_type_name_maping(db_sys_params->shelf);
if (db_sys_params->shelf == INTERNAL) {
shelf = get_internal_shelf_name_maping(db_sys_params->platform);
}
snprintf(buffer, MAX_SIZE,frmt, mode, version,
get_platform_name_maping(db_sys_params->platform),
shelf,
get_drive_name_maping(db_sys_params->drive));
return buffer;
}
Valgrind говорит:
=5241== Thread 11:
==5241== Invalid read of size 1
==5241== at 0x3295847D0C: vfprintf (in /lib64/libc-2.12.so)
==5241== by 0x329586F631: vsnprintf (in /lib64/libc-2.12.so)
==5241== by 0x329584F102: snprintf (in /lib64/libc-2.12.so)
==5241== by 0x5A9BB9: generate_sql_query_for_epic_cache (cache.c:85)
==5241== by 0x5AA592: read_on_limits_epic_data_from_db (cache.c:239)
==5241== by 0x586037: insert_on_limit_record_in_ultra_cache (ultra_cache.c:81)
==5241== by 0x5868B3: init_ultra_cache_on_limit_epic (ultra_cache.c:213)
==5241== by 0x586A5B: init_db_ultra_cache (ultra_cache.c:248)
==5241== by 0x59D577: do_sizing (ws.c:3585)
==5241== by 0x405F3F: csi2__getsizing_json (forward_sizer.c:529)
==5241== by 0x49D7B1: soap_serve_csi2__getsizing_json (soapServer.c:156)
==5241== by 0x49CD75: soap_serve_request (soapServer.c:87)
==5241== Address 0x7802d30 expected vs actual:
==5241== Expected: unknown
==5241== Actual: stack array "key_epic" of size 1,024 in frame 3 back from here
MAX_SIZE определяется как: #define MAX_SIZE 1024