On 11/16/2010 02:29 PM, Dhaval Giani wrote:
> The same counter is reused in an inner loop in cg_prepare_cgroup.
> This is perfectly fine simply because we never exit the inner
> loop to the outer loop. The only way out of the inner loop leads
> to a return statement, during which there is no mention of the
> outer counter.
>
> However, this is ugly code, and hard to read and may lead to bugs
> if some decides to refactor the code. So clean it all up using a
> different counter.
>
> Thanks to Steve Grubb for raising this issue at
> http://article.gmane.org/gmane.comp.lib.libcg.devel/2485
>
> Reported-by: Steve Grubb<[email protected]>
> Signed-off-by: Dhaval Giani<[email protected]>
Acked-By: Jan Safranek <[email protected]>
>
> ---
> src/api.c | 11 ++++++-----
> 1 file changed, 6 insertions(+), 5 deletions(-)
>
> Index: libcg/src/api.c
> ===================================================================
> --- libcg.orig/src/api.c
> +++ libcg/src/api.c
> @@ -2204,6 +2204,7 @@ static int cg_prepare_cgroup(struct cgro
>
> /* Scan all the controllers */
> for (i = 0; i< CG_CONTROLLER_MAX; i++) {
> + int j = 0;
> if (!controllers[i])
> return 0;
> controller = controllers[i];
> @@ -2212,16 +2213,16 @@ static int cg_prepare_cgroup(struct cgro
> * controllers. */
> if (strcmp(controller, "*") == 0) {
> pthread_rwlock_rdlock(&cg_mount_table_lock);
> - for (i = 0; i< CG_CONTROLLER_MAX&&
> - cg_mount_table[i].name[0] != '\0'; i++) {
> + for (j = 0; j< CG_CONTROLLER_MAX&&
> + cg_mount_table[j].name[0] != '\0'; j++) {
> cgroup_dbg("Adding controller %s\n",
> - cg_mount_table[i].name);
> + cg_mount_table[j].name);
> cptr = cgroup_add_controller(cgroup,
> - cg_mount_table[i].name);
> + cg_mount_table[j].name);
> if (!cptr) {
> cgroup_dbg("Adding controller '%s'"
> " failed\n",
> - cg_mount_table[i].name);
> + cg_mount_table[j].name);
>
> pthread_rwlock_unlock(&cg_mount_table_lock);
> cgroup_free_controllers(cgroup);
> return ECGROUPNOTALLOWED;
>
>
------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3.
Spend less time writing and rewriting code and more time creating great
experiences on the web. Be a part of the beta today
http://p.sf.net/sfu/msIE9-sfdev2dev
_______________________________________________
Libcg-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libcg-devel