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

  • Home
  • SEARCH
  • 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 4110252
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:54:36+00:00 2026-05-20T21:54:36+00:00

Hey, while trying to iterate with next as a pointer in my structure, it

  • 0

Hey, while trying to iterate with “next” as a pointer in my structure, it loops forever for no reason, even if i try to make a fake pointer to the structure (not with calling a function to set it up)

my code:

void
command_login(conn,msg)
  void *conn;
  const char *msg;
{
  const char *u,*p;
  char *home;
  ConnectionQueue* q;
  DBResult *result;
  DBResult *tmp;
  bool got_pass,got_user,admin;
  if (!conn)
    return;

  /* initalize */
  q = (ConnectionQueue *)conn;
  got_pass = false; got_user = false; admin = false;
  result = NULL;
  tmp = NULL;
  if (msg == NULL || *msg == '\0'){
    send_socket(q->conn,"LOGIN: Invalid user and password\n");
    return;
  }

  (void)strtok((char *)msg," ");
  u = strtok((char *)NULL, " ");
  p = strtok((char *)NULL, " ");
  if (!u || !p){
    send_socket(q->conn,"LOGIN: Invalid user or password\n");
    return;
  }

  printf("command_login(): u = %s, p = %s\n",u,p);
  tmp = store_query("SELECT * FROM `users`");
  if (!tmp){
    /* should never happen */
    send_socket(q->conn,"LOGIN: Failed to fetch results\n");
    return;
   }

   printf("command_login(): Checking user and password...\n");
   result = tmp;
  while (result != NULL){
     if (!got_user){
       if (strcmp(result->field_name,"user") == 0 && strcmp(result->field_value,u) == 0)
         got_user = true;
     }else if (!got_pass){
       if (strcmp(result->field_name,"pass") == 0){
          if (strcmp(result->field_value,transform_password(p)) == 0)
            got_pass = true;
       }
     }else if (!admin){
       if (strcmp(result->field_name,"admin") == 0){
         admin = boolean_string(result->field_value);
       }
     }else{
       break;
     }
     result = result->next;
  }

  free_result(result);
  printf("command_login(): Checking got user and got password\n");
  if (!got_user || !got_pass){
    send_socket(q->conn,"LOGIN: Invalid user or password\n");
    return;
  }

  printf("command_login(): Login successfully\n");
  send_socket(q->conn,"LOGIN: Success\n");
  q->conn->state &= ~S_NEED_LOGIN;
  q->admin = admin;
#ifndef _WIN32
  home = getenv("HOME");
#else
  home = getenv("HOMEPATH");
#endif
  if (!home)
    return;

  if (!chdir(home)){
    send_socket(q->conn,"LOGIN: Failed to change to user home directory %s: %s\n",home,strerror(errno));
    close_connection(q->conn);
    return;
   }
   send_socket(q->conn,"CWD: %s\n",home);
}

it loops forever here:

  while (result != NULL){
     if (!got_user){
       if (strcmp(result->field_name,"user") == 0 && strcmp(result->field_value,u) == 0)
         got_user = true;
     }else if (!got_pass){
       if (strcmp(result->field_name,"pass") == 0){
          if (strcmp(result->field_value,transform_password(p)) == 0)
            got_pass = true;
       }
     }else if (!admin){
       if (strcmp(result->field_name,"admin") == 0){
         admin = boolean_string(result->field_value);
       }
     }else{
       break;
     }
     result = result->next;
  }

any ideas? thanks

  • 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-05-20T21:54:37+00:00Added an answer on May 20, 2026 at 9:54 pm

    When you create a new DBResult structure, do you set the next pointer to NULL? If you create the structure with malloc, your test for result would never end.

    It’s really difficult to know more without knowing the definition of DBResult and the definition of store_query. What does store_query return?

    You say you are making a list. In store_query you don’t actually set next of ret to tmp. I assume that is what you want to do. Look carefully at your list construction because it is not correct.

    It might help to draw a picture of your DBResult as it gets constructed.

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

Sidebar

Related Questions

hey guys I just started trying to convert my query structure to PDO and
Hey guys, i'm really trying to understand regular expressions while scraping a site, i've
Hey everyone. While I'm trying to learn some PHP and mySQL, I ran into
Hey all. I've been been trying to figure this out for a while now.
Hey, I'm trying to make an Address book for my site and I was
Hey, I'm Trying to make a programa in C++ that generate triangle, square and
Hey, I'm trying to make a basic hockey style game. I have the basic
Hey all. Newbie question time. I'm trying to setup JMXQuery to connect to my
Hey having some trouble trying to maintain transparency on a png when i create
Ok, so I'm trying to make a nice superclass for data-access objects that can

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.