Use proper constant for ULONG_MAX instead of typecasting -1