Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.18 KB | None | 0 0
  1. typedef struct _config_main_section ConfigMainSection;
  2.  
  3. struct _config_main_section {
  4.     const char *name;
  5.     char **list;
  6.     size_t size;
  7. };
  8.  
  9. static char *config_files[] = { CONFIG_FILES_LOG, CONFIG_FILES_ERR, CONFIG_FILES_PID };
  10. static char *config_general[] = { CONFIG_GENERAL_NAME, CONFIG_GENERAL_DESCRIPTION };
  11.  
  12.  
  13. static ConfigMainSection sections[] = {
  14.         { CONFIG_FILES, config_files, ARRAY_SIZE(config_services_files) },
  15.         { CONFIG_GENERAL, config_general, ARRAY_SIZE(config_services_general) },
  16. };
  17.  
  18.  
  19. int func(void) {
  20.     // array_size returns correct value (2), currentSection->name is a proper char*
  21.     ConfigMainSection *main_section = find_config_main_section(sections, ARRAY_SIZE(sections),currentSection->name);
  22. }
  23.  
  24. ConfigMainSection *find_config_main_section(ConfigMainSection *sections[], size_t size, const char *name) {
  25.     ConfigMainSection *ptr = sections;
  26.     ConfigMainSection *endPtr = sections + size;
  27.     while (ptr < endPtr) {
  28.         if(stricmp(ptr->name,name) == 0) {
  29.             // I would expect that at some point, a matching name is found and a pointer to ConfigMainSection is returned
  30.             // yet this point is never reached (segfault)
  31.             return ptr;
  32.         }
  33.         ptr++;
  34.     }
  35.     return NULL;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement