From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by sourceware.org (Postfix) with ESMTPS id 4D9D4385AE62 for ; Fri, 24 Jun 2022 10:10:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4D9D4385AE62 Received: by mail-ed1-x530.google.com with SMTP id o10so2793402edi.1 for ; Fri, 24 Jun 2022 03:10:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:reply-to :from:date:message-id:subject:to:cc; bh=yQCj+gLjLVDxMY63psJRUzhGsqAe2SG6BVU58d+AB3U=; b=cdoKDUtywhNRb5kR+D0vV/H7VIl3t7Emy1ybsly6JWM/QsPyRYn4dfHtcSq1qCrYi8 3lbZ2f2Pu8iibXmKUdxsOp6OiywjTm1TIkAd1kkT5IochtN6yxcpyoUCnZVdvql3haTr SUrE30QZZA6epR1kkDsIXV1PmR0ldyH4J9zNW7VfLVFUy/UOi0VpCGUw2nVu/38cWwfR y5wFAmbSjK5bU0hobYHlyk/xj05lefpMvX69MVspOyXjuZ94VFxMkSHbuRVUi7kvmlix Wta4AFypGmwBXib8lG2DFzgjNWJg7aKFCMZL3UiY3rmtXeRsmNZEK9gbAK7tYRJ6X0WL HRqA== X-Gm-Message-State: AJIora+j2d4sLpMY5l3trTkkSHF9Nybt3WZIlXxMQYRHu+LJOVw2Bxy1 222dVwPRQabq4pyvPSueXloqPnBj3HvYd62ROAE= X-Google-Smtp-Source: AGRyM1sZM1iR/SVMyC3dfFav0iUt2DCdjUeR22o9/pgFNTM5y/USZymUx/pgIHARXZRgzqbellWe3tuUWNfdYw5FHkY= X-Received: by 2002:a05:6402:1e88:b0:435:bf05:f0f with SMTP id f8-20020a0564021e8800b00435bf050f0fmr12840777edf.2.1656065457078; Fri, 24 Jun 2022 03:10:57 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Reply-To: cauldwell.thomas@gmail.com From: Frederick Virchanza Gotham Date: Fri, 24 Jun 2022 11:10:46 +0100 Message-ID: Subject: Re: string::iterator should have more error checking To: Jonathan Wakely Cc: "libstdc++" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Jun 2022 10:11:00 -0000 On Fri, Jun 24, 2022 at 10:35 AM Jonathan Wakely wrote: > That's expected. The contents of the string_view are a string literal, > which is in the program image, not on the heap. Valgrind is the best tool for troubleshooting heap problems (although it's useless against non-heap problems). > AddressSanitizer > doesn't check access to such memory. > The byte after the string literal "brush" is uninitialized, but it > does exist in a valid memory page. Check out how "-fsanitize" flags the following invalid access to static-duration constexpr arrays: https://godbolt.org/z/fjnPTWj5P Having thought about this a little more, I realise that "brush" in memory is: char constexpr brush[6u] = { 'b', 'r', 'u', 's', 'h', '\0' }; And so therefore it is perfectly valid to access the null terminator located at brush[5u], which is why the access is not flagged by "-fsanitize". > And it's not detected by Debug Mode because string_view iterators are > just pointers. I understand that. I think there should be "" and that it should be optionally configurable to barf when it encounters a null terminator. (It must be optionally configurable because a null char is actually a valid char inside a string_view). Something like: #define _GLIBCXX_STRINGVIEW_DONT_ALLOW_NULL_CHAR #include