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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:36:57+00:00 2026-06-02T07:36:57+00:00

Initially I want to convert this uint8_t array to a char array in c.

  • 0

Initially I want to convert this uint8_t array to a char array in c. I have been a little stuck trying to resolve this problem. My first alternative solution is to copy another type value to the temporary one, copy the tmp value to a writable char, and then remove tmp value from memory. By the way this is used to accompany a blake hash function. Here is my code snippet:

char * bl(char *input)
{
    uint8_t  output[64];
    char msg[]= "";
    char *tmp;

    int dInt;

    memset(output,0,64);
    tmp = (char*) malloc(64);
    if (!tmp){
            exit( 1);
    }

    dInt = strlen(input);

    if (dInt > 0xffff){
            exit( 1);
    }
    uint8_t data[dInt];

    memset(data,0, dInt);
    strlcpy(data,input,dInt);
    uint64_t dLen =dInt;
    blake512_hash(output, data,dLen);

    int k;
    for (k=0;k<64;k++){
            tmp[k] = output[k];  //does this "copy" is buggy code?
    }

    memcpy(msg, tmp,64);
    //so here I can to delete tmp value
    // I dont want there were left unused value in memory
    // delete tmp;  
    free(tmp);

    return  msg;
}

I think the code above is still not efficient, so what are your opinion, hints and the fixes?
Thank you very much before!

  • 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-02T07:37:05+00:00Added an answer on June 2, 2026 at 7:37 am

    First of all, you should never return a pointer to a local variable since the variable will be destroyed by the time the function exits. You should probably want to pass the output array to bl function and use that to output the string.

    For most cases(if uint8_t IS char, which is usually the case), memcpy(msg, output, 64) should be sufficient. If you want to be strict about it(quite frankly blake512_hash shouldn’t return uint8_t array in the first place if you are expecting char array as the output all the time), you could simply call msg[k] = (char)tmp[k] in your for loop and remove memcpy.

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

Sidebar

Related Questions

i want to have a foreach loop where the initial array is changed inside
I want to have an image that would initially be black and white, but
I have a TCHAR array in my C++ code which I want to assign
For example I have an array of 200 integers. What I want to do
I want to make a movieclip invisible initially but i dont want to set
How can I increment numeric String value? If it is initially 1, I want
I have a scientific application for which I want to input initial values at
Ok so I have an OpenFileDialog and I want to set the initial directory
I have a Windows CE console application that's entry point looks like this int
I have been given a task to create a bridge between C# and Java.

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.