/* NULL terminate before asking the length of path[] */
path[PATH_MAX-1] = '\0';
i_len = strlen(&path[0]);
- if( i_len == PATH_MAX )
- i_len--; /* truncate to prevent buffer overflow */
+ /* Protect against buffer overflow:
+ * max index is PATH_MAX-1 and we increment by 1 after
+ * so PATH_MAX-2 is the bigest we can have */
+ if( i_len > PATH_MAX - 2 )
+ i_len = PATH_MAX - 2;
#if defined(WIN32) || defined(UNDER_CE)
if( (i_len > 0) && path[i_len] != '\\' )
path[i_len] = '\\';