Re: [PATCH v5 2/3] advice: revamp advise API

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Junio C Hamano <gitster@xxxxxxxxx> writes:

> Emily Shaffer <emilyshaffer@xxxxxxxxxx> writes:
>
>>> ...  Your get_config_value() would then become a mere lookup
>>> in advice_setting[] array, e.g.
>>> 
>>> 	int advice_enabled(unsigned advice_type)
>>> 	{
>>> 		static int initialized;
>>> 
>>> 		if (!initialized) {
>>> 			initialized = 1;
>>> 			git_config(populate_advice_settings, NULL);
>>> 		}
>>> 		if (ARRAY_SIZE(advice_setting) <= advice_type)
>>> 			BUG("OOB advice type requested???");
>>> 		return !advice_setting[advice_type].disabled;
>>> 	}
>>> 
>>> with your "push-update-rejected has two names" twist added.

One beauty of the approach is that the "twist" can be done in the
initialization codepath, e.g.

 	int advice_enabled(unsigned advice_type)
 	{
 		static int initialized;
 
 		if (!initialized) {
 			initialized = 1;
 			git_config(populate_advice_settings, NULL);

                        advice_setting[ADVICE_PUSH_UPDATE_REJECTED] &=
                        advice_setting[ADVICE_PUSH_UPDATE_REJECTED_ALIAS];
 		}
 		if (ARRAY_SIZE(advice_setting) <= advice_type)
 			BUG("OOB advice type requested???");
 		return !advice_setting[advice_type].disabled;
 	}

which means that the function literally becomes an array access that
is guarded for out-of-bounds index.

Thanks, Emily, for making me look at the suggested code again to
realize this ;-)



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux