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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:05:51+00:00 2026-06-10T11:05:51+00:00

==3139== Conditional jump or move depends on uninitialised value(s) ==3139== at 0x4A0673F: strcpy (mc_replace_strmem.c:311)

  • 0

==3139== Conditional jump or move depends on uninitialised value(s)

==3139== at 0x4A0673F: strcpy (mc_replace_strmem.c:311)

==3139== by 0x400ADB: htable_insert (hashtable.c:56)

==3139== by 0x400F25: main (mylib.c:11)

Hi everybody, I’m still trying to insert into a hash table. I can’t quite get it to work, i’ve included my print method, just because i thought it might be a problem. I’m trying to do linear probing. When I ran valgrind, I got this error, I think it has something to do with copying into my string, but I’m not really sure what is means? I really don’t at this point know how to get this insertion working, some input would be wonderful..
Line 56 in hashtable insert is strcpy(str, key)

int htable_insert(htable h, char *str) {
   int i;
   /*convert string to integer*/
   unsigned int index = htable_word_to_int(str);
   /*calculate index to insert into hash table*/
   int remainder = index%h->capacity;
   /*once calculated position in the hash table, 3 possibilities occur*/
   /*no string in this positon, copy string to that position, increment number of keys, return 1*/
   if (h->key[remainder] == NULL) {
      char *key = emalloc(strlen(str) + 1);
      strcpy(str, key);
      h->key[remainder] = key;
      h->frequencies[remainder] = 1;
      h->num_keys++;
      return 1;
   }
   /*the exact same string is at the position, increment frequency at that position, return frequency*/
   if (strcmp(str, h->key[remainder]) == 0) {
      h->frequencies[remainder]++;
      return h->frequencies[remainder];
   }/*a string is at that position, but it isnt the rightone, keep moving along the array
      until you find either an open space or the string you are looking for*/
   if (h->key[remainder] != NULL && strcmp(str, h->key[remainder]) != 0) {
      /*you may need to wrap back around to the beginning of the table, so each time you add
        to the position you should also mod by the table capacity.*/
      for (i = 0; i <= h->capacity; i++) {
         /*no string in this positon, copy string to that position, increment number of keys*/
         if (h->key[remainder] == NULL) {
            char *key = emalloc(strlen(str) + 1);
            strcpy(str, key);
            h->key[remainder] = key;
            h->frequencies[remainder] = 1;
            h->num_keys++;
         }
         /*if you find the string you were looking for, increment the frequecny at the position
           and return the frequency*/
         if (strcmp(str, h->key[remainder]) == 0) {
            h->frequencies[remainder]++;
            return h->frequencies[remainder];
         }
         if (h->key[remainder] != NULL && h->capacity ==  i) {
            i = 0;
         }
      }   
   }
   /*if you have kept looking for an open space but there isnt one, the hash table must fu*/
   return 0;
}

void htable_print(htable h, FILE *stream) {
   int i;
   for(i = 0; i < h->capacity; i++) {
      if(h->key[i] != NULL) {
         fprintf(stream, "%d%s\n", h->frequencies[i], h->key[i]);
      }
   }
}
  • 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-10T11:05:52+00:00Added an answer on June 10, 2026 at 11:05 am

    Your strcpy’s should be strcpy(key, str) and not the other way around. (You can just use strdup, btw, and save the malloc+strcpy).

    Also, in:
    if (h->key[remainder] != NULL && strcmp(str, h->key[remainder]) != 0) {

    The condition “h->key[remainder] != NULL” is redundant: you’ve already checked that above.

    Finally, in your loop (going over the buckets), it seems like:

    1. The loop condition should be <, not <=
    2. You should be incrementing remainder somewhere, or use “remainder+i” and the index to h->keys
    3. Instead of “capacity==i” –> “i=0”, just use “(remainder+i)%capacity” as the index to h->keys

    .. Finally finally — the initial part, the one that’s outside the loop, could be in the loop, saving code.

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

Sidebar

Related Questions

Here is some example data in a mysql table a b distance 15 44
I am trying to perform auto scaling on Amazon EC2 with below commands: elb-create-lb
when i run development server it works very well, even an empty project runing
I have a file like this: 01 00 01 14 c0 00 01 10
I need to be able to insert a proxy between my application and the
I am new to awk programming and little confused about the use of NR
Recently seen in my (Snow Leopard) Mac Mini's /var/log/secure.log : Feb 17 06:31:32 mini
I'm just playing around with hbase( on EC2) and am having a problem when
I figured it wouldn't work, but i just uploaded my program file from local
I am working on a simple invoicing and accounting applications, but I am totally

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.