cloudberry icon indicating copy to clipboard operation
cloudberry copied to clipboard

[Bug] appendonlyam_handler.c:1790:25: error: ‘segfile_count’ may be used uninitialized

Open avamingli opened this issue 8 months ago • 7 comments

Apache Cloudberry version

main branch commit: 644b4e307380954e986f048d0a7910a3063e524e

What happened

appendonlyam_handler.c: In function ‘appendonly_index_build_range_scan’:
appendonlyam_handler.c:1790:25: error: ‘segfile_count’ may be used uninitialized [-Werror=maybe-uninitialized]
 1790 |                         FreeAllSegFileInfo(seginfo, segfile_count);
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
aocsam_handler.c: In function ‘aoco_index_build_range_scan’:
aocsam_handler.c:1952:25: error: ‘segfile_count’ may be used uninitialized [-Werror=maybe-uninitialized]
 1952 |                         FreeAllAOCSSegFileInfo(seginfo, segfile_count);
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

What you think should happen instead

No response

How to reproduce

config, make

Operating System

Ubuntu

Anything else

No response

Are you willing to submit PR?

  • [ ] Yes, I am willing to submit a PR!

Code of Conduct

avamingli avatar Mar 12 '25 06:03 avamingli

make failed, and something bad may be behind the failure, because segfile_count is not assigned any more. It's assigned before as:

	/*
	 * When Parallel index build,there is no additional operation to update the number of tuples
	 * that supports this logic. Uniform processing is used here. 
	 */ 
	if (progress)
	{
		seginfo = GetAllFileSegInfo(heapRelation, snapshot, &segfile_count, NULL);
		for (int seginfo_no = 0; seginfo_no < segfile_count; seginfo_no++)
		{
			total_blockcount += seginfo[seginfo_no]->varblockcount;
		}
		pgstat_progress_update_param(PROGRESS_SCAN_BLOCKS_TOTAL, total_blockcount);
	}

git blame show that it's changed by https://github.com/apache/cloudberry/pull/897

@reshke @yjhjstz @x4m @my-ship-it @leborchuk

avamingli avatar Mar 12 '25 06:03 avamingli

Also if (!FIPS_mode_set)(in contrib/pgcrypto/openssl.c) will got an WError..

jiaqizho avatar Mar 12 '25 06:03 jiaqizho

pls merge https://github.com/apache/cloudberry/pull/986 asap.

yjhjstz avatar Mar 12 '25 13:03 yjhjstz

Maybe we should configure CI with more strict compiler flags... LGTM #986

reshke avatar Mar 12 '25 14:03 reshke

/*
	 * When Parallel index build,there is no additional operation to update the number of tuples
	 * that supports this logic. Uniform processing is used here. 
	 */ 
	if (progress)
	{
		seginfo = GetAllFileSegInfo(heapRelation, snapshot, &segfile_count, NULL);
		for (int seginfo_no = 0; seginfo_no < segfile_count; seginfo_no++)
		{
			total_blockcount += seginfo[seginfo_no]->varblockcount;
		}
		pgstat_progress_update_param(PROGRESS_SCAN_BLOCKS_TOTAL, total_blockcount);
	}

@reshke this need to check, I will merge quick fix https://github.com/apache/cloudberry/pull/986. issue keep open here. @avamingli

yjhjstz avatar Mar 13 '25 02:03 yjhjstz

and something bad may be behind the failure, because segfile_count is not assigned any more. It's assigned before as:

	/*
	 * When Parallel index build,there is no additional operation to update the number of tuples
	 * that supports this logic. Uniform processing is used here. 
	 */ 
	if (progress)
	{
		seginfo = GetAllFileSegInfo(heapRelation, snapshot, &segfile_count, NULL);
		for (int seginfo_no = 0; seginfo_no < segfile_count; seginfo_no++)
		{
			total_blockcount += seginfo[seginfo_no]->varblockcount;
		}
		pgstat_progress_update_param(PROGRESS_SCAN_BLOCKS_TOTAL, total_blockcount);
	}

git blame show that it's changed by #897

@reshke @yjhjstz @x4m @my-ship-it @leborchuk

Could someone please review this?

avamingli avatar Mar 14 '25 06:03 avamingli

Upstream does this different way: https://github.com/greenplum-db/gpdb-archive/blob/main/src/backend/access/aocs/aocsam_handler.c#L2335 looks like we need to cherry-pick block directory support and restore this logic https://github.com/greenplum-db/gpdb-archive/blob/main/src/backend/access/aocs/aocsam_handler.c#L2196 i will take another look soon

reshke avatar Mar 19 '25 03:03 reshke