Linux Kernel Error - linux

I got the same errors on these lines
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];
How can I fix this?
I am using kernel version 2.6.32-24-generic
It is my one of function and above four errors are from this function...
It is an insertion function of AVL tree.
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;
}

current is a macro that expands into a function call:
static __always_inline struct task_struct *get_current(void)
{
return this_cpu_read_stable(current_task);
}
#define current get_current()
Use some other variable name.

Related

How does the second argument use a variable when using bpf_probe_read_kernel_str() in ebpf?

`
size_t pos = 0;
const u32 MAX_BACKTRACE_DEPTH = 20;
for (u32 cnt = MAX_BACKTRACE_DEPTH; cnt != 0; --cnt) {
if (err || curr_dentry == NULL) {
break;
}
int name_len = BPF_CORE_READ(curr_dentry, d_name.len);
const u8 *name = BPF_CORE_READ(curr_dentry, d_name.name);
if (name_len <= 1) {
break;
}
if (name_len + pos > 512) {
break;
}
name_len = bpf_probe_read_kernel_str(filename + pos, name_len, name);
if (name_len <= 1) {
break;
}
pos += name_len;
filename[pos - 1] = '/';
struct dentry *temp_dentry = BPF_CORE_READ(curr_dentry, d_parent);
if (temp_dentry == curr_dentry || temp_dentry == NULL) {
break;
}
curr_dentry = temp_dentry;
}
`
ebpf validator prompts "R2 unbounded memory access, use 'var &= const' or 'if (var < const)'" when the second argument to function bpf_probe_read_kernel_str is a variable.
I tried to add const to name_len and I couldn't.
You need to have a strict bound on that name_len variable. It is currently only bounded by 512 - pos which is not a constant.

How to escape HTML special characters in Solidity?

I am trying the approach below. It is based on some of Uniswap's code.
I am curious as to whether it will work at reasonable cost or whether there is a better way.
function escapeHTML(string memory input)
public
pure
returns (string memory)
{
bytes memory inputBytes = bytes(input);
uint extraCharsNeeded = 0;
for (uint i = 0; i < inputBytes.length; i++) {
bytes1 currentByte = inputBytes[i];
if (currentByte == "&") {
extraCharsNeeded += 4;
} else if (currentByte == "<") {
extraCharsNeeded += 3;
} else if (currentByte == ">") {
extraCharsNeeded += 3;
}
}
if (extraCharsNeeded > 0) {
bytes memory escapedBytes = new bytes(
inputBytes.length + extraCharsNeeded
);
uint256 index;
for (uint i = 0; i < inputBytes.length; i++) {
if (inputBytes[i] == "&") {
escapedBytes[index++] = "&";
escapedBytes[index++] = "a";
escapedBytes[index++] = "m";
escapedBytes[index++] = "p";
escapedBytes[index++] = ";";
} else if (inputBytes[i] == "<") {
escapedBytes[index++] = "&";
escapedBytes[index++] = "l";
escapedBytes[index++] = "t";
escapedBytes[index++] = ";";
} else if (inputBytes[i] == ">") {
escapedBytes[index++] = "&";
escapedBytes[index++] = "g";
escapedBytes[index++] = "t";
escapedBytes[index++] = ";";
} else {
escapedBytes[index++] = inputBytes[i];
}
}
return string(escapedBytes);
}
return input;
}

Non-void function error

I'm trying to compile this program in c (for a cs50 online class), and keep getting the following error:
fifteen.c:233:1: error: control may reach end of non-void function [-Werror,-Wreturn-type]
}
I'm not asking about the logic of my code, but more looking for the syntax error that I've been missing for the last hour. Code is below. Thanks!
bool move(int tile)
{
for (int i = 0; i < d - 1; i++){
for (int j= 0; j < d - 1; j++){
if (tile == board[i][j]){
if (board[i+1][j] == tile){
board[i+1][j] = 0;
board[i+1][j] = tile;
return true;
}
else if (board [i-1][j] == 0){
board[i-1][j] = tile;
board [i-1][j] = 0;
return true;
}
else if (board [i][j+1] == 0){
board[i][j+1] = tile;
board [i][j+1] = 0;
return true;
}
else if (board [i][j-1] == 0){
board[i][j-1] = tile;
board [i][j-1] = 0;
return true;
}
}
return false;
}
}
}
This error is saying that your method can reach the end without returning a value. This is happening in this case because your brackets are out of place.
Try the following:
bool move(int tile) {
for (int i = 0; i < d - 1; i++) {
for (int j = 0; j < d - 1; j++) {
if (tile == board[i][j]) {
if (board[i+1][j] == tile) {
board[i+1][j] = 0;
board[i+1][j] = tile;
return true;
}
else if (board [i-1][j] == 0){
board[i-1][j] = tile;
board [i-1][j] = 0;
return true;
}
else if (board [i][j+1] == 0){
board[i][j+1] = tile;
board [i][j+1] = 0;
return true;
}
}
else if (board [i][j-1] == 0){
board[i][j-1] = tile;
board [i][j-1] = 0;
return true;
}
}
}
return false;
}

How to detect window state in linux?

I need to find out if a native linux application window is maximized or minimized in a java program.
I tried using X11.XGetWindowProperty() and I get some results also, but I cant make out any useful information in it.
I am using JNA 4.2.1, Java 8 update72 on Ubuntu 14.04 LTS. Any pointers will be very helpful. Thanks in advance to all.
[Edit]
I have the code below which gives me the result I need. But the result is not same for every invocation. The atoms which are returned for the window vary within invocations. Is there any other reliable way to get the window state?
private static X11 x11 = X11.INSTANCE;
private static Display dispy = x11.XOpenDisplay(null);
public static void main(String[] args) {
try {
X11.Atom[] atoms = getAtomProperties(
bytesToInt(getProperty(X11.XA_ATOM, X11.INSTANCE.XInternAtom(dispy, "_NET_WM_STATE", false))));
boolean hidden = false;
boolean vmax = false;
boolean hmax = false;
for (int i = 0; i < atoms.length; i++) {
X11.Atom atom = atoms[i];
if (atom == null)
continue;
String atomName = X11.INSTANCE.XGetAtomName(dispy, atom);
if ("_NET_WM_STATE_HIDDEN".equals(atomName)) {
hidden = true;
} else if ("_NET_WM_STATE_MAXIMIZED_VERT".equals(atomName)) {
vmax = true;
} else if ("_NET_WM_STATE_MAXIMIZED_HORZ".equals(atomName)) {
hmax = true;
}
}
if (hidden)
System.out.println("Window minimized");
else if (vmax && hmax && !hidden)
System.out.println("Window maximized");
else
System.out.println("Window normal");
} catch (X11Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static X11.Atom[] getAtomProperties(int[] ids) {
X11.Atom[] atoms = new X11.Atom[ids.length];
for (int i = 0; i < ids.length; i++) {
if (ids[i] == 0)
continue;
atoms[i] = new X11.Atom(ids[i]);
}
return atoms;
}
private static int[] bytesToInt(byte[] prop) {
if (prop == null)
return null;
int[] res = new int[prop.length / 4];
for (int i = 0; i < res.length; i++) {
res[i] = ((prop[i * 4 + 3] & 0xff) << 24) | ((prop[i * 4 + 2] & 0xff) << 16) | ((prop[i * 4 + 1] & 0xff) << 8)
| ((prop[i * 4 + 0] & 0xff));
if (res[i] != 0)
continue;
}
return res;
}
private static byte[] getProperty(X11.Atom xa_prop_type, X11.Atom xa_prop_name) throws X11Exception {
X11.Window window = new X11.Window(73400355);
X11.AtomByReference xa_ret_type_ref = new X11.AtomByReference();
IntByReference ret_format_ref = new IntByReference();
NativeLongByReference ret_nitems_ref = new NativeLongByReference();
NativeLongByReference ret_bytes_after_ref = new NativeLongByReference();
PointerByReference ret_prop_ref = new PointerByReference();
NativeLong long_offset = new NativeLong(0);
NativeLong long_length = new NativeLong(4096 / 4);
/*
* MAX_PROPERTY_VALUE_LEN / 4 explanation (XGetWindowProperty manpage):
*
* long_length = Specifies the length in 32-bit multiples of the data to be retrieved.
*/
if (x11.XGetWindowProperty(dispy, window, xa_prop_name, long_offset, long_length, false, xa_prop_type, xa_ret_type_ref,
ret_format_ref, ret_nitems_ref, ret_bytes_after_ref, ret_prop_ref) != X11.Success) {
String prop_name = x11.XGetAtomName(dispy, xa_prop_name);
throw new X11Exception("Cannot get " + prop_name + " property.");
}
X11.Atom xa_ret_type = xa_ret_type_ref.getValue();
Pointer ret_prop = ret_prop_ref.getValue();
if (xa_ret_type == null) {
// the specified property does not exist for the specified window
return null;
}
if (xa_ret_type == null || xa_prop_type == null || !xa_ret_type.toNative().equals(xa_prop_type.toNative())) {
x11.XFree(ret_prop);
String prop_name = x11.XGetAtomName(dispy, xa_prop_name);
throw new X11Exception("Invalid type of " + prop_name + " property");
}
int ret_format = ret_format_ref.getValue();
long ret_nitems = ret_nitems_ref.getValue().longValue();
// null terminate the result to make string handling easier
int nbytes;
if (ret_format == 32)
nbytes = Native.LONG_SIZE;
else if (ret_format == 16)
nbytes = Native.LONG_SIZE / 2;
else if (ret_format == 8)
nbytes = 1;
else if (ret_format == 0)
nbytes = 0;
else
throw new X11Exception("Invalid return format");
int length = Math.min((int) ret_nitems * nbytes, 4096);
byte[] ret = ret_prop.getByteArray(0, length);
x11.XFree(ret_prop);
return ret;
}

How can I make start again after gameover?? (Processing)

I want to make this game in Processing.
When in 'Switch' those are displayed case0,1,2 in same time.
I don't know how to edit it.
and after case2(gameover), press key '1' to start again.
but I think it goes to case1 when gameover situation...
How can I edit it??
PImage work[] = new PImage[3];
float workSize[] = new float[3];
float workX[] = new float[3];
float workY[] = new float[3];
float workS[] = new float[3];
PImage handA, handB;
PFont font;
int level;
boolean gameover = false;
boolean selected[] = new boolean [3];
int salary = 0;
void setup(){
size(1000,800);
background(255);
imageMode(CENTER);
for (int i=0; i<3; i++) {
workX[i] = random(0, width);
workY[i] = random(0, height);
selected[i] = false;
workSize[i] = 120;
}
handA = loadImage("handA.png");
handB = loadImage("handB.png");
work[0] = loadImage("work0.png");
work[1] = loadImage("work1.png");
work[2] = loadImage("work2.png");
font = createFont("Gulim", 48);
textFont(font);
textAlign(CENTER, CENTER);
}
void draw(){
background(255);
if (mousePressed) {
cursor(handB, 0, 0);
} else {
cursor(handA, 0, 0);
}
switch (level) {
default: // press'1' to start game
fill(0);
text("1을 눌러 일 얻기", width/2, height/2);
if (key == '1') {
level = 1;
}
break;
case 1:
game();
if (gameover == true) {
level = 2;
}
break;
case 2: // press '1' to start again
fill(0);
text("퇴직금 : "+ salary + " + (비정규직으로 퇴직금 없음)", width/2, height/2-100);
text("일을 못해서 정리해고", width/2, height/2);
text("1을 눌러 다시 일 얻기", width/2, height/2+100);
if (key == '1') {
level = 1;
}
break;
}
}
void game() {
for (int i=0; i<3; i++) {
float clickedDist = dist(workX[i], workY[i], mouseX, mouseY);
if (clickedDist<workSize[i]/2 && mousePressed) {
workSize[i] = workSize[i] - 2;
} else {
workSize[i] = workSize[i] + 0.7;
}
if (workSize[i]<100) {
workSize[i] = 0;
}
if (workSize[i]>400) {
gameover = true;
}
if (workSize[i] == 0 && selected[i] == false) {
salary = salary + 50;
selected[i] = true;
workX[i] = random(0, width);
workY[i] = random(0, height);
selected[i] = false;
workSize[i] = 120;
}
if (salary > 150) {
workS[i] = workSize[i] + 0.5;
workSize[i] = workS[i];
}
if (abs(mouseX-workX[i]) < workSize[i]/2 && abs(mouseY-workY[i]) < workSize[i]/2) {
workX[i] += random(-5,5);
workY[i] += random(-5,5);
}
image(work[i], workX[i], workY[i], workSize[i], workSize[i]);
pushMatrix();
fill(0);
textSize(48);
text("봉급 : "+ salary, textWidth("salary"), (textAscent()+textDescent()/2));
popMatrix();
}
}
All you have to do is reset any variables that store the state of your game, such as your level variable. Something like this:
void keyPressed(){
if(gameover && key == '1'){
gameover = false;
level = 1;
}
}

Resources