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 8062887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:49:38+00:00 2026-06-05T10:49:38+00:00

I have some code which is like this (This is not production code. Just

  • 0

I have some code which is like this (This is not production code. Just a sample code)

char *inbuf = NULL;
inbuf = buf; //buf is some other valid buffer of size 100.

func(&inbuf);


.....

void func(char **p)
{
  ...
  (*p)++;
  ...

}

Coverity Tool says that “Taking address with &inbuf yields a singleton”. I have heard the term singleton with respect to C++. But, what does a singleton pointer mean in terms of C?

  • 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-05T10:49:40+00:00Added an answer on June 5, 2026 at 10:49 am

    What does a singleton pointer mean in terms of C?

    In this case I think Coverity is referring to the difference between an array of char* and a pointer to a single char* created by taking the address of that array.

    Coverity is warning you that by passing the address of the first element of buf to func, you’re making it more difficult for yourself to safely write to that array because you can’t easily determine its size.

    It’s difficult to be sure without seeing all of your code, but assuming buf is an array you’ve declared somewhere in your top-level function then using the sizeof operator on buf from that function will yield the size of the array.

    However, when you pass the address of buf to func at the line

    func(&inbuf); 
    

    …func merely receives a pointer to the first element of that array. From func you can no longer use sizeof to determine the size of the array – it will just return the size of the pointer – and so you can’t safely write to that pointer without some implicit understanding of how much space the array contains.

    This makes for fragile code, and hence is poor practice.

    (None of this is anything to do with the Singleton Pattern)

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

Sidebar

Related Questions

I have some Java code which looks roughly like this: String urlString = ftp://polar.ncep.noaa.gov/pub/history/waves/multi_1.glo_30m.dp.200601.grb2;
I have some code which I would like to pass instances or classes interchangeably.
I have some code which is been running by a backgroundworker I'd like some
I have some auto-instantiation code which I would like to apply to about 15
I have been given some generated code which looks like so: <form id=form1 method=post
I have some code that references an outside DLL which in production will be
I have some code which has comments after each method saying this for example:
I have some code which iteratively appends data to a file and looks similar
I have some code which populates a hashtable with a question as the key
I have some code which handles data files and reports an error when it

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.