Fix segfault by invalid margin value