Print this page
OS-2444 richmond hardware maps need to support ivy bridge (review fixes)

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/fm/topo/libtopo/common/topo_string.c
          +++ new/usr/src/lib/fm/topo/libtopo/common/topo_string.c
↓ open down ↓ 62 lines elided ↑ open up ↑
  63   63          size_t seplen = strlen(sep);
  64   64          const char *scanstart;
  65   65          char *token;
  66   66          char *ret;
  67   67  
  68   68          if (input != NULL) {
  69   69                  /*
  70   70                   * Start scanning at beginning of input:
  71   71                   */
  72   72                  scanstart = input;
  73      -        } else {
       73 +        } else if (*lastp == NULL) {
  74   74                  /*
  75   75                   * If we have already finished scanning, return NULL.
  76   76                   */
  77      -                if (*lastp == NULL)
  78      -                        return (NULL);
  79      -
       77 +                return (NULL);
       78 +        } else {
  80   79                  /*
  81   80                   * Otherwise, start scanning where we left off:
  82   81                   */
  83   82                  scanstart = *lastp;
  84   83          }
  85   84  
  86   85          token = strstr(scanstart, sep);
  87   86          if (token != NULL) {
  88   87                  /*
  89   88                   * We still have a separator, so advance the next-start
  90   89                   * pointer past it:
  91   90                   */
  92   91                  *lastp = token + seplen;
  93   92                  /*
  94      -                 * Copy out this element:
       93 +                 * Copy out this element.  The buffer must fit the string
       94 +                 * exactly, so that topo_hdl_strfree() can determine its
       95 +                 * size with strlen().
  95   96                   */
  96   97                  ret = topo_hdl_alloc(hdl, token - scanstart + 1);
  97   98                  (void) strncpy(ret, scanstart, token - scanstart);
  98   99                  ret[token - scanstart] = '\0';
  99  100          } else {
 100  101                  /*
 101  102                   * We have no separator, so this is the last element:
 102  103                   */
 103  104                  *lastp = NULL;
 104  105                  ret = topo_hdl_strdup(hdl, scanstart);
↓ open down ↓ 211 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX