Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1saGYS-007YIo-OG for pgsql-hackers@arkaria.postgresql.org; Sat, 03 Aug 2024 15:20:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1saGYR-005xWb-4D for pgsql-hackers@arkaria.postgresql.org; Sat, 03 Aug 2024 15:20:23 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1saGYQ-005xWT-QZ for pgsql-hackers@lists.postgresql.org; Sat, 03 Aug 2024 15:20:22 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1saGYO-002wuE-9q for pgsql-hackers@postgresql.org; Sat, 03 Aug 2024 15:20:22 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 473FKD164169219; Sat, 3 Aug 2024 11:20:13 -0400 From: Tom Lane To: Heikki Linnakangas cc: Peter Eisentraut , pgsql-hackers Subject: Re: Fix inappropriate uses of atol() In-reply-to: <0d3b4dfa-afa2-4f1c-9b30-e2acbdeb2e64@iki.fi> References: <0d3b4dfa-afa2-4f1c-9b30-e2acbdeb2e64@iki.fi> Comments: In-reply-to Heikki Linnakangas message dated "Sat, 03 Aug 2024 17:07:46 +0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <4169217.1722698413.1@sss.pgh.pa.us> Date: Sat, 03 Aug 2024 11:20:13 -0400 Message-ID: <4169218.1722698413@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Heikki Linnakangas writes: > On 03/08/2024 14:04, Peter Eisentraut wrote: >> I noticed (during [0]) to some uses of the function atol() seem >> inappropriate. > +1 except for this one: >> /* If we have just one character this is not a string */ >> - if (atol(p->type->size) == 1) >> + if (atoi(p->type->size) == 1) >> mmerror(PARSE_ERROR, ET_ERROR, "invalid data type"); How about - if (atol(p->type->size) == 1) + if (strcmp(p->type->size, "1") == 0) ? I've not actually tested, but this should catch the cases the warning is meant to catch while not complaining about any of the examples you give. I'm not sure if leading/trailing spaces would fool it (i.e., "char foo[ 1 ];"). But even if they do, that doesn't seem disastrous. regards, tom lane