Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8359447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:08:49+00:00 2026-06-09T11:08:49+00:00

While reading the answers to this SO question , I learned that out-of-bounds pointer

  • 0

While reading the answers to this SO question, I learned that out-of-bounds pointer arithmetic is undefined. Indeed, according to C99 6.5.6 paragraph 8

If both the
pointer operand and the result point to elements of the same
array object, or one past the last element of the array
object, the evaluation shall not produce an overflow;
otherwise, the behavior is undefined.

Does freeing that object invalidate that guarantee? 7.20.3.2 “The Free Function” Doesn’t seem to mention it, simply mentioning that “the space is deallocated”. Since 6.5.6 specifically mentions overflow, it seems like an integer overflow issue, which free wouldn’t affect. Is arithmetic on a pointer to an object an act of “referring to it”?

In other words, is:

char *foo = malloc(10);
free(foo);
foo++;

Undefined? Or is the usage of “overflow” a different one?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T11:08:51+00:00Added an answer on June 9, 2026 at 11:08 am

    C99 §6.2.4 says:

    The value of a pointer becomes indeterminate when the object it points
    to reaches the end of its lifetime.

    §7.20.3 describes the lifetime of allocated objects, as created by malloc():

    The lifetime of an allocated object extends from the allocation until
    the deallocation.

    So, formally speaking, the value of the pointer foo becomes indeterminate after the free(), and therefore can no longer be said to point to any object. The behaviour of the increment is therefore undefined.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While reading answers to this question I noticed that answers ( this for example)
While reading the answers to this question I got a doubt regarding the default
This is a question that came to mind while reading the brilliant answer by
While reading this class BitmapFactory I noticed that almost all methods inside are static.
While I was reading the accepted answer of this question , I had the
While reading this question , I came across @Johannes 's answer. template<typename> struct void_
After reading the nice answers in this question , I watched the screencasts by
I was reading the answers to this question C++ pros and cons and got
While reading the K&R 2nd edition I noticed that the programs always began with
While reading through another question here, on creating a URL shortening service, it was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.