On November 17, 2017 11:20:45 PM GMT+01:00, Qing Zhao <qing.z...@oracle.com> wrote: > >> On Nov 16, 2017, at 6:24 PM, Martin Sebor <mse...@gmail.com> wrote: >>> >>> In my current local implementation, I used the following routine to >get the range info: (and use the MINMAXLEN[1]+1 for the length of the >non-constant string) >>> >>> /* Determine the minimum and maximum value or string length that ARG >>> refers to and store each in the first two elements of MINMAXLEN. >>> For expressions that point to strings of unknown lengths that are >>> character arrays, use the upper bound of the array as the maximum >>> length. For example, given an expression like 'x ? array : "xyz"' >>> and array declared as 'char array[8]', MINMAXLEN[0] will be set >>> to 3 and MINMAXLEN[1] to 7, the longest string that could be >>> stored in array. >>> Return true if the range of the string lengths has been obtained >>> from the upper bound of an array at the end of a struct. Such >>> an array may hold a string that's longer than its upper bound >>> due to it being used as a poor-man's flexible array member. */ >>> >>> bool >>> get_range_strlen (tree arg, tree minmaxlen[2]) >>> { >>> } >>> >>> However, this routine currently miss a very obvious case as the >following: >>> >>> char s[100] = {'a','b','c','d’}; >>> >>> __builtin_strcmp(s, "abc") != 0 >>> >>> So, I have to change this routine to include such common case. >> >> There was a discussion some time ago about converting CONSTRUCTOR >> trees emitted for array initializers like the above to STRING_CST >> (see bug 71625 for some background). I think that would still be >> the ideal solution. Then you wouldn't have to change >> get_range_strlen.
IIRC Martin had a patch for this. Richard. >thanks for the info, Martin. > >In my case, it’s the size of “100” cannot be collected in the >MINMAXLEN[1] for the string “s”. > >I need to make sure that the size of variable string s is larger than >the size of constant string “abc” to guarantee the safety of the >transformation. > >currently, “get_range_strlen” cannot identify the simple VAR_DECL with >array_type to determine the maximum size of the string. > >Qing >> >> Martin