소스 검색

UBI: eliminate possible undefined behaviour

The assignment to pos when rb is finally NULL is undefined behaviour.
Upon seeing that assignment, GCC may assume that rb is not NULL, and
the loop condition ``rb'' may be optimised away.

Signed-off-by: Phil Carmody <ext-phil.2.carmody@nokia.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Phil Carmody 16 년 전
부모
커밋
758d8e4634
1개의 변경된 파일2개의 추가작업 그리고 1개의 파일을 삭제
  1. 2 1
      drivers/mtd/ubi/ubi.h

+ 2 - 1
drivers/mtd/ubi/ubi.h

@@ -579,7 +579,8 @@ void ubi_do_get_volume_info(struct ubi_device *ubi, struct ubi_volume *vol,
 	for (rb = rb_first(root),                                            \
 	     pos = (rb ? container_of(rb, typeof(*pos), member) : NULL);     \
 	     rb;                                                             \
-	     rb = rb_next(rb), pos = container_of(rb, typeof(*pos), member))
+	     rb = rb_next(rb),                                               \
+	     pos = (rb ? container_of(rb, typeof(*pos), member) : NULL))
 
 /**
  * ubi_zalloc_vid_hdr - allocate a volume identifier header object.