From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: from minnie.tuhs.org (minnie.tuhs.org [50.116.15.146]) by inbox.vuxu.org (Postfix) with ESMTP id C96112400D for ; Fri, 20 Sep 2024 21:40:27 +0200 (CEST) Received: from minnie.tuhs.org (localhost [IPv6:::1]) by minnie.tuhs.org (Postfix) with ESMTP id 5B6E1437D2; Sat, 21 Sep 2024 05:40:21 +1000 (AEST) Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) by minnie.tuhs.org (Postfix) with ESMTPS id BECDC437C8 for ; Sat, 21 Sep 2024 05:40:14 +1000 (AEST) Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-a8a706236bfso140172866b.0 for ; Fri, 20 Sep 2024 12:40:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726861213; x=1727466013; h=mime-version:user-agent:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=71h+WWl4zKKdreCx5WkCZ8bXJdyTInL8dW6r/thj27o=; b=R2mpwHvQHCvjdfo7zliqGxpRuPnZSJKO/M+0TutHqKN2Q58sAXRiEoH4ns6Cpq6C4y rIEU4ai3h7KA+CdbpE/KScX3u6YE6L6q+LCSo7CcaeoLQP2wZxpf+dMnHG2z55bdEJZF WIhFYF2QV1pgExNsK4eCKLMwZmBQ7Yrd1qaJyTw1nZp8eRYRcdjy4ZYDARESZcZPSVVD D4Uhxl2Fdz0VZwlamFxY6b7yInJuPO6d4pvJUW+yf9ZNguI5jwF8AljGmKXYqL+TkrZT NnjB6VJWKny++0R0uwTAL/mqD4EI7Ezx8bVol84onObQP5dd2NvvfL943rxcoBz6vYWo Qdzw== X-Forwarded-Encrypted: i=1; AJvYcCWCdHoO7GsTQeG3+kPmkkeAlIykHWtbzlGgbLSw9HtwXQTGa3gppW3M7TngJ4FFdY9/lCWb@tuhs.org X-Gm-Message-State: AOJu0YwnsAsh1GvChFpI2e6VRtrVrhHnKKOuC4YocHucif9HVl4O4EKC ROiSG7Vt+F/novnkgBFRUkoB436X5VwdVcrFKCrjB3NOTbMdmVXb X-Google-Smtp-Source: AGHT+IEbWCRFPTKjxCkoW9byMKty9C6We6QGgleQDGJM/9sN8bhKCXKDjKSs4NtBxqh4wxB9eYXhDw== X-Received: by 2002:a05:6402:42cb:b0:5c3:d0e1:9f81 with SMTP id 4fb4d7f45d1cf-5c46484f429mr4460154a12.7.1726861213087; Fri, 20 Sep 2024 12:40:13 -0700 (PDT) Received: from hera.home.vuxu.org (hera.home.vuxu.org. [2a0e:46c4:2400:1ea4:fe5c:eeff:fe11:5f50]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c42bb497adsm7485935a12.14.2024.09.20.12.40.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Sep 2024 12:40:12 -0700 (PDT) Received: from localhost (hera.home.vuxu.org [local]) by hera.home.vuxu.org (OpenSMTPD) with ESMTPA id 19f4ccd5; Fri, 20 Sep 2024 19:40:10 +0000 (UTC) From: Leah Neukirchen To: Rich Salz In-Reply-To: (Rich Salz's message of "Thu, 19 Sep 2024 09:13:11 -0400") References: Date: Fri, 20 Sep 2024 21:40:10 +0200 Message-ID: <871q1e5d2d.fsf@vuxu.org> User-Agent: Gnus/5.13 (Gnus v5.13) MIME-Version: 1.0 Content-Type: text/plain Message-ID-Hash: KINLTX6AI53HGID6IANCINSMBNHL3NRL X-Message-ID-Hash: KINLTX6AI53HGID6IANCINSMBNHL3NRL X-MailFrom: chneukirchen@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-tuhs.tuhs.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Douglas McIlroy , TUHS main list X-Mailman-Version: 3.3.6b1 Precedence: list Subject: [TUHS] Re: Maximum Array Sizes in 16 bit C List-Id: The Unix Heritage Society mailing list Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Rich Salz writes: >> >> if there need to be negative references in array accesses (which certainly >> makes sense to me, on its face), it seems reasonable to have whatever >> intermediate variable be signed. >> > > In my first C programming job I saw the source to V7 grep which had a > "foo[-2]" construct. It was a moment of enlightenment and another bit of > K&R fell into place. ( > https://www.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/cmd/grep.c; search > for "[-") Now this thread already derailed into C undefined behavior semantics, but nobody bothered to look at the actual code, which is perfectly fine: if ((c = *sp++) != '*') lastep = ep; switch (c) { ... case '[': ... neg = 0; if((c = *sp++) == '^') { neg = 1; c = *sp++; } cstart = sp; do { ... if (c=='-' && sp>cstart && *sp!=']') { for (c = sp[-2]; c<*sp; c++) ep[c>>3] |= bittab[c&07]; sp++; } ep[c>>3] |= bittab[c&07]; } while((c = *sp++) != ']'); Since sp has been incremented twice already, accessing sp[-2] is fine in any case, but it's also guarded by cstart, so the regexp range "[-z]" doesn't expand to [[-z]. -- Leah Neukirchen https://leahneukirchen.org/