Re: [PATCH v5 1/3] perf report: compile tips.txt in perf binary

From: Denys Zagorui -X (dzagorui - GLOBALLOGIC INC at Cisco)
Date: Fri May 21 2021 - 06:24:44 EST


> that still does not solve that we set MAX_TIPS and have
> no way of checking that's still valid
>
> how about something like below (completely untested):

Yes, looks good, i've tested it.
>
>
> static const char *perf_tip(void)
> {
> char *start = _binary_Documentation_tips_txt_start;
> char *tok, *tmp, *prev;
> int pick, size;
>
> size = _binary_Documentation_tips_txt_end - start;
> pick = random() % size;
>
> _binary_Documentation_tips_txt_start[size - 1] = 0;
>
> for (tok = strtok_r(start, "\n", &tmp); tok;
> tok = strtok_r(NULL, "\n", &tmp)) {
> if (pick < (tok - start))
> return prev;
> prev = tok;
> }
>
> return prev;
> }
>
> this way you wouldn't need array with MAX_TIPS defined