From 31a7e22aa6cb68bd36de3e4ccbc3da3484dfee67 Mon Sep 17 00:00:00 2001 From: Pepijn de Vos Date: Mon, 23 Sep 2024 13:54:55 +0200 Subject: [PATCH] fix nullptr check --- common/kernel/relptr.h | 2 ++ himbaechel/uarch/gowin/cst.cc | 6 +++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/common/kernel/relptr.h b/common/kernel/relptr.h index f0f45b7d..4a98dd68 100644 --- a/common/kernel/relptr.h +++ b/common/kernel/relptr.h @@ -33,6 +33,8 @@ template struct RelPtr const T *get() const { return reinterpret_cast(reinterpret_cast(this) + offset); } + bool is_null() const { return offset == 0; } + const T &operator[](std::size_t index) const { return get()[index]; } const T &operator*() const { return *(get()); } diff --git a/himbaechel/uarch/gowin/cst.cc b/himbaechel/uarch/gowin/cst.cc index 26f1ac7a..f6ee1378 100644 --- a/himbaechel/uarch/gowin/cst.cc +++ b/himbaechel/uarch/gowin/cst.cc @@ -241,7 +241,7 @@ struct GowinCstReader }; -void add_sip_constraints(Context *ctx, const Extra_package_data_POD *extra) { +static void add_sip_constraints(Context *ctx, const Extra_package_data_POD *extra) { for(auto cst : extra->cst) { auto it = ctx->cells.find(IdString(cst.net)); if (it == ctx->cells.end()) { @@ -260,8 +260,8 @@ void add_sip_constraints(Context *ctx, const Extra_package_data_POD *extra) { bool gowin_apply_constraints(Context *ctx, std::istream &in) { // implicit constraints from SiP pins - const Extra_package_data_POD *extra = reinterpret_cast(ctx->package_info->extra_data.get()); - if(extra != nullptr) { + if(!ctx->package_info->extra_data.is_null()) { + const Extra_package_data_POD *extra = reinterpret_cast(ctx->package_info->extra_data.get()); add_sip_constraints(ctx, extra); }