2014-03-29 153 views
1

我得到了在這些線路上Linux內核錯誤

error: lvalue required as left operand of assignment 

line 49: for (current = root; current != NULL; ptr = current) { 

line 50: current =current->link[res]; 

line 75: for (current = bf; current != newnode; res = link_dir[++i]) { 

line 80: current = current->link[res]; 

line 167: current = root; 

line 192: current = current->link[res]; 

我怎樣才能解決這個同樣的錯誤?

我使用的內核版本2.6.32-24-通用

這是我的功能,上述四大誤區一個從這個函數... 它是AVL樹的插入功能。

static void insertion (char value[]) { 
     struct AVLTree_Node *bf, *parent_bf, *subtree, *temp; 
     struct AVLTree_Node *current, *parent, *newnode, *ptr; 
     int res = 0,i=0 ,num=100, compareLimit = 100; 
     char link_dir[32]; 

     if (!root) { 
       root = createNode(value); 
       return; 
     } 

     bf = parent_bf; 
     parent_bf = root; 
     // find the location for inserting the new node 
     for (current = root; current != NULL; ptr = current) { 
      current =current->link[res]; 
       num = strcmp(value,current->data); 
       if (num == 0) { 
         printk(KERN_INFO "Cannot insert duplicates!!\n"); 
         return; 
       } 
       int result = strncmp(value,current->data, compareLimit); 
       if(result > 0) 
         res = 1; 
       else if(result <= 0) 
         res =0; 
       parent = current; 

       if (current->bfactor != 0) { 
         bf = current; 
         parent_bf = ptr; 
         i = 0; 
       } 
       link_dir[i++] = res; 
     } 
     // create the new node 
     newnode = createNode(value); 
     parent->link[res] = newnode; 
     res = link_dir[i = 0]; 
     // updating the height balance after insertion 
     for (current = bf; current != newnode; res = link_dir[++i]) { 
       if (res == 0) 
         current->bfactor--; 
       else 
         current->bfactor++; 
       current = current->link[res]; 
     } 

     // right sub-tree 
     if (bf->bfactor == 2) { 
       printk(KERN_INFO "bfactor = 2\n"); 
       temp = bf->link[1]; 
       if (temp->bfactor == 1) {     
         subtree = temp; 
         bf->link[1] = temp->link[0]; 
         temp->link[0] = bf; 
         temp->bfactor = bf->bfactor = 0; 
       } else { 
         subtree = temp->link[0]; 
         temp->link[0] = subtree->link[1]; 
         subtree->link[1] = temp; 
         bf->link[1] = subtree->link[0]; 
         subtree->link[0] = bf; 
         // update balance factors 
         if (subtree->bfactor == -1) { 
           bf->bfactor = 0; 
           temp->bfactor = 1; 
         } else if (subtree->bfactor == 0) { 
           bf->bfactor = 0; 
           temp->bfactor = 0; 
         } else if (subtree->bfactor == 1) { 
           bf->bfactor = -1; 
           temp->bfactor = 0; 
         } 
         subtree->bfactor = 0; 
       } 
     // left sub-tree 
     } else if (bf->bfactor == -2) { 
       temp = bf->link[0]; 
       if (temp->bfactor == -1) { 

         // single rotation(SR) right 

         subtree = temp; 
         bf->link[0] = temp->link[1]; 
         temp->link[1] = bf; 
         temp->bfactor = bf->bfactor = 0; 
       } else { 
         // double rotation - (SR left + SR right) 

         subtree = temp->link[1]; 
         temp->link[1] = subtree->link[0]; 
         subtree->link[0] = temp; 
         bf->link[0] = subtree->link[1]; 
         subtree->link[1] = bf; 
         // update balance factors 
         if (subtree->bfactor == -1) { 
           bf->bfactor = 1; 
           temp->bfactor = 0; 
         } else if (subtree->bfactor == 0) { 
           bf->bfactor = 0; 
           temp->bfactor = 0; 
         } else if (subtree->bfactor == 1) { 
           bf->bfactor = 0; 
           temp->bfactor = -1; 
         } 
         subtree->bfactor = 0; 
       } 
     } else { 
       return; 
     } 

     if (bf == root) { 
       root = subtree; 
       return; 
     } 
     if (bf != parent_bf->link[0]) { 
       parent_bf->link[1] = subtree; 
     } else { 
       parent_bf->link[0] = subtree; 
     } 
     return; 
} 
+0

'Linux內核錯誤'你用內核做什麼?你如何得到這個錯誤?我認爲在編譯一些代碼時會出現編譯錯誤。因此需要編寫代碼。 –

+0

請點擊這裏把更多的信息,因爲它是很難回答的時候你不喜歡你在做什麼提供充分的信息,當這種情況發生時,你編譯的內核版本等 –

+1

謝謝回覆爵士.. 請重新看到帖子。 –

回答

1

current是一個宏,expands成一個函數調用:

static __always_inline struct task_struct *get_current(void) 
{ 
     return this_cpu_read_stable(current_task); 
} 

#define current get_current() 

使用一些其他的變量名。

+1

謝謝先生,它的工作原理... –