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

The Archive Base Latest Questions

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

I can’t figure out what I’m doing wrong. I am learning C so sorry

  • 0

I can’t figure out what I’m doing wrong. I am learning C so sorry if this is obviously wrong, but I’m trying to use uthash to make a hash map of stocks and their prices. But when I add stocks to my hash map, I get the above error.

What I did was take the example from their site and ran it to make sure it worked, once it worked as expected I changed the values to fit my problem. In the original code, the variable id in the struct was an integer but I changed it to a char(instead of number, I wanted to use the stock ticker as the key), then I started to the following errors:

../src/stackCsamples.c:87: warning: passing argument 1 of '__builtin_object_size' makes pointer from integer without a cast
../src/stackCsamples.c:87: warning: passing argument 1 of '__builtin_object_size' makes pointer from integer without a cast
../src/stackCsamples.c:87: warning: passing argument 1 of '__builtin___strcpy_chk' makes pointer from integer without a cast
../src/stackCsamples.c:87: warning: passing argument 1 of '__inline_strcpy_chk' makes pointer from integer without a cast
../src/stackCsamples.c:89: warning: passing argument 1 of 'strlen' makes pointer from integer without a cast
../src/stackCsamples.c:89: warning: passing argument 1 of 'strlen' makes pointer from integer without a cast
../src/stackCsamples.c:89: warning: passing argument 1 of 'strlen' makes pointer from integer without a cast

The problem seems to be with two lines here(87) which is strcpy(s->id, user_id); and (89) which is: HASH_ADD_STR( users, id, s );

How am I using both of these wrong? I looked strcpy up and it looks like it takes 3 items, but when I add the size I still get errors.

Here’s a snippet of the parts I think are relevant:

#include <stdio.h>   /* gets */
#include <stdlib.h>  /* atoi, malloc */
#include <string.h>  /* strcpy */
#include "uthash.h"

struct my_struct {
    char id;                    /* key */
    float price;
    UT_hash_handle hh;         /* makes this structure hashable */
};

struct my_struct *users = NULL;

void new_stock(char *user_id, float price) {
    struct my_struct *s;

    s = (struct my_struct*)malloc(sizeof(struct my_struct));
    strcpy(s->id, user_id);
    s->price = price;
    HASH_ADD_STR( users, id, s );  /* id: name of key field */
}

int main() {
    printf("starting..");
    new_stock("IBM", 10.2);
    new_stock("goog", 2.2);
    return 0;
}
  • 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-05T00:49:36+00:00Added an answer on June 5, 2026 at 12:49 am

    You need to provide enough space in the structure for the user ID array, or dynamically allocate enough space. For instance, you might do:

    enum { MAX_ID_LEN = 32 };
    struct my_struct
    {
        char id[MAX_ID_LEN];                    /* key */
        float price;
        UT_hash_handle hh;         /* makes this structure hashable */
    };
    

    Then you could use:

    strcpy(s->id, user_id);
    

    as long as you’ve checked that user_id is not longer than 31 characters plus null before hand. If you’ve not done that check, you should. If you refuse to do that check and don’t mind truncating overlong user ID strings, then you could use:

    strncpy(s->id, user_id, sizeof(s->id) - 1);
    s->id[sizeof(s->id)-1] = '\0';
    

    This ensures null termination; just using strncpy() alone does not. Beware, if the string (s->id) was much longer, you could find your code wasting time zeroing out the tail end of the string.


    The residual warnings about strlen() are hidden by the HASH_ADD_STR() macro, but likely come from the same problem as the strcpy() warnings did — the s->id field was not a character pointer or a character array. The amended structure will likely quash those warnings too. For us to be sure, you’d have to show the definition of HASH_ADD_STR() and any macros it invokes.

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

Sidebar

Related Questions

Can't figure out how to do this in a pretty way : I have
Can't work out a way to make an array of buttons in android. This
Can anyone help me trying to find out why this doesn't work. The brushes
can I make my own headers in HTTP request ? e.g. This is normal
Can I figure out if a function has already been assigned to an event?
can someone show me the regex for this preg_match. I want to make sure
can anyone help me in trying to check whether JavaScript is enabled in client
Can this be done? It seems like this should be possible. In general, I
Can somebody help me with this. There is HTML code: <h3> <label> <input type=checkbox
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

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.