From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86917C433FE for ; Wed, 26 Oct 2022 15:11:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234488AbiJZPLT (ORCPT ); Wed, 26 Oct 2022 11:11:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234439AbiJZPLO (ORCPT ); Wed, 26 Oct 2022 11:11:14 -0400 Received: from mail-qv1-xf2a.google.com (mail-qv1-xf2a.google.com [IPv6:2607:f8b0:4864:20::f2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE7968A7FD for ; Wed, 26 Oct 2022 08:11:09 -0700 (PDT) Received: by mail-qv1-xf2a.google.com with SMTP id u7so11681441qvn.13 for ; Wed, 26 Oct 2022 08:11:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=eT2uz8tUG/sofl6nuodiNAwatRFoHDNx9Z1BojLryfg=; b=lHC8D0Zhnqe3uE9yu0bdgopEQXVZ+h7wdNuabF2dxkye0OmeQoY4GBzpd7XzCJpljY PSEsmSxTsMUU6v+CBOF4LJVm1jSdZfqutAlgrBP7iWpevfzn9tMe223LkVOD22I0KRjG 1Rq2GomVkEu3b2DM0EeYz1mYLHdItTSUtsQan6PXvNVA9GxhRr+Upt+JvHSewPzvOKy0 iG9OIgrQmNKhl1o1CqtWLPW8rXrqtbZ6wmABElscWaR3VT/ukr3lx7v5LXyMkXdinVz/ fsmLrSqzmQAD86yNTcUEIJ1PVpiFnLOyfJHjfbUTieXBeK6FONXGCPEBb3PhOJTgf+uS /eKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=eT2uz8tUG/sofl6nuodiNAwatRFoHDNx9Z1BojLryfg=; b=CyknhFZQvFp+g8NF6rXVILejLGy2THGvmd2E0PZbhar8JXli7NXdOSfCGApz5BLXGi GFKwwdpiPyCPkGP34lcwuJa1vJP8hBnj++pNbUE3YjIeOmtTJ/PLcSuh5PrMNr+uxEJi P9JBJg1BOW3q18fcaVQwhy5Qp9/b6OOAcQInp5sgCnaLevzy8QdE+ugE1iUrBpVvYg3h mSC4g8oT4qeB1RgtHqLigU12AhnWG5Hff0uUZs0Ijtxe48wNFb5TOpiPbgAiXIovDfgr e+mjc/uquG9LSt14NOjINyTvyCZphWdw+qMiKfoQt+jb0CYbn9A4lASQotvJiL2DqABe Coeg== X-Gm-Message-State: ACrzQf21bWJSQwpfFVe6bzF0AyoZ9Cd4guQBVugBIlfQYyj5mfhup3N6 UIHf5UiXDmX9TD7z+Zf66ivNGCw0bY7O1Q== X-Google-Smtp-Source: AMsMyM6Yn+1KOEK89O0iT2HyiWTicc/woCgenW2nBrNU7zFODjOEF8s+kOgrUppy9Wku0TzcXnhcnw== X-Received: by 2002:a17:902:cf08:b0:17d:46b6:25f9 with SMTP id i8-20020a170902cf0800b0017d46b625f9mr44701685plg.67.1666797057642; Wed, 26 Oct 2022 08:10:57 -0700 (PDT) Received: from google.com (7.104.168.34.bc.googleusercontent.com. [34.168.104.7]) by smtp.gmail.com with ESMTPSA id 66-20020a630545000000b0043a0de69c94sm2910520pgf.14.2022.10.26.08.10.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Oct 2022 08:10:57 -0700 (PDT) Date: Wed, 26 Oct 2022 15:10:53 +0000 From: Sean Christopherson To: "Wang, Wei W" Cc: Vipin Sharma , "pbonzini@redhat.com" , "dmatlack@google.com" , "andrew.jones@linux.dev" , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH v6 3/5] KVM: selftests: Add atoi_paranoid() to catch errors missed by atoi() Message-ID: References: <20221021211816.1525201-1-vipinsh@google.com> <20221021211816.1525201-4-vipinsh@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On Wed, Oct 26, 2022, Wang, Wei W wrote: > On Saturday, October 22, 2022 5:18 AM, Vipin Sharma wrote: > > +int atoi_paranoid(const char *num_str) > > +{ > > + char *end_ptr; > > + long num; > > + > > + errno = 0; > > + num = strtol(num_str, &end_ptr, 10); > > Why not use strtoull here? This intended to be a drop in replacement for atoi(), which allows negative numbers. > Negative numbers will result in a huge "unsigned long long" number, > and this will be captured by your TEST_ASSERT(num >= INT_MIN) below. As above, we want to allow negative numbers, e.g. memslot_perf_test.c uses '-1' to indicate "as many slots as possible". It's unlikely a test will As unlikely as > Then we don't need patch 4, I think. Even if this low level helper disallowed negative numbers, patch 4 still has value in that the wrappers make the code self-documenting, i.e. makes it very obvious what input values are allowed.