[LTP] [PATCH v2 1/2] Refactoring aio-stress.c using LTP API

Petr Vorel pvorel@suse.cz
Tue Jan 4 09:34:46 CET 2022


Hi Andrea,

...
>  			for (i = 0; i < io->io_oper->reclen; i++) {
>  				if (io->buf[i] != verify_buf[i]) {
> -					fprintf(stderr, "%d:%c:%c ", i,
> -						io->buf[i], verify_buf[i]);
> +					ret = asprintf(&msg, "%d:%c:%c ", i, io->buf[i], verify_buf[i]);
> +					if (ret < 0)
> +						tst_brk(TBROK, "asprintf memory allocation error");
> +					ptr += sprintf(ptr, msg);
Actually, this is problematic for -Werror=format-security which we use in CI.
Simple "%s" fixes that. It can be done before merge.

ptr += sprintf(ptr, "%s", msg); 

@Richie: I wonder if make check could also actually compile the code with
extra CFLAGS from build.sh.

...
>  	for (i = 0; i < DEVIATIONS; i++) {
> -		fprintf(stderr, " %.0f < %d", lat->deviations[i],
> -			deviations[i]);
> +		ret = asprintf(&msg, " %.0f < %d", lat->deviations[i], deviations[i]);
> +		if (ret < 0)
> +			tst_brk(TBROK, "asprintf memory allocation error");
> +		ptr += sprintf(ptr, msg);
And here as well.

>  		total_counted += lat->deviations[i];
> +		free(msg);
>  	}
> -	if (total_counted && lat->total_io - total_counted)
> -		fprintf(stderr, " < %.0f", lat->total_io - total_counted);
> -	fprintf(stderr, "\n");
> +
> +	if (total_counted && lat->total_io - total_counted) {
> +		ret = asprintf(&msg, " < %.0f", lat->total_io - total_counted);
> +		if (ret < 0)
> +			tst_brk(TBROK, "asprintf memory allocation error");
> +		ptr += sprintf(ptr, msg);
and here.

Kind regards,
Petr


More information about the ltp mailing list