diff --git a/lib/libsgm/src/census_transform.cu b/lib/libsgm/src/census_transform.cu
index df38886181b91ff7c1c5901a06ef8f5325a85047..d437f978e76300587e4b06e2d7954420a35dd1a2 100644
--- a/lib/libsgm/src/census_transform.cu
+++ b/lib/libsgm/src/census_transform.cu
@@ -134,7 +134,8 @@ __global__ void census_transform_kernel(
 		}
 	}
 
-	dest[x+y*width] = res;
+	// FIXME: Should use feature pitch, not width.
+	if (x < width && y < height) dest[x+y*width] = res;
 }
 
 template <typename T>